Candle Documentation

Static File Router

Example showing how to use the static router to serve serve static files with Wick. This example serves the current working directory as the root of the server.

This app configuration starts off with the common Application kind and a name field.

kind: wick/app@v1
name: static_file_server

Note: All HTTP routers must be configured with a path that acts as a simple filter to determine which router to execute. Routers are executed in top-down order. A router configured with path: "/" will match all traffic so should be defined at the end of the router configuration.

Static Routers require a Volume resource that serves as the root directory the router will serve files from.

resources:
- name: DIR
  resource:
    kind: wick/resource/volume@v1
    path: '{{ ctx.env.PWD }}'

The router configuration itself takes the volume resource by the given name alongside a path to proxy from.

routers:
- kind: wick/router/static@v1
  path: /
  volume: DIR

The full configuration is located at examples/http/staticfile-router.wick. Run this application locally by cloning the wick repository and using wick run (or cargo run -p wick-cli -- run to run from source)

git clone https://github.com/candlecorp/wick && cd wick
wick run examples/http/staticfile-router.wick

Complete Example

Note: Examples may require environment variables and execution from within the wick project’s root to access any local files.

The full example configuration is included below,

#!/usr/bin/env wick
---
kind: wick/app@v1
name: static_file_server
metadata:
  description: Example showing how to use the static router to serve serve static files with Wick. This example serves the current working directory as the root of the server.
  version: 0.0.1
  authors:
    - 'Wick Maintainers'
  vendors:
    - 'Candle Corporation'
  licenses:
    - Apache-2.0
resources:
  - name: http
    resource:
      kind: wick/resource/tcpport@v1
      port: '8999'
      address: 0.0.0.0
  - name: DIR
    resource:
      kind: wick/resource/volume@v1
      path: '{{ ctx.env.PWD }}'
triggers:
  - kind: wick/trigger/http@v1
    resource: http
    routers:
      - kind: wick/router/static@v1
        path: /
        volume: DIR