Skip to content

4. Static file serving

Evgeny Abramovich edited this page Nov 25, 2023 · 2 revisions

You can configure directories with static files for each mapping, which can be useful for running a local version of a SPA application or replacing specific static files. The static file configuration is done on a per-mapping basis using the following structure:

mappings:
  - from: ...
    to: ...
    statics:
      - path: /assets
        dir: ~/project/assets
        index: index.html
      - path: /static
        dir: ~/project/data

The configuration includes the following properties:

path - Specifies the path where the static files will be served. Wildcards are not supported.

dir - Specifies the path to the folder from which the static files will be served.

index - Optional property that specifies the file to be returned if the requested file is not found. It should be a relative path within the dir folder. By default, this property is not set.

These static file configurations allow you to customize the serving of static files for each mapping. The index property is used to define the fallback file to be returned if the requested file is not found. Please note that the relative path specified in index should be within the folder specified in the dir property.

SPA mode

In this mode, all requests that start with the path specified in the path property will be handled by the static file handler. If a request does not match any of the files, the file specified in the index property will be returned. This behavior is commonly used in SPA (Single-Page Application) applications where all requests are directed to the scripts in the index.html file, which process the requests.

To configure this mode, simply specify the desired file in the index property. Keep in mind that this file must be located in the folder specified in the dir property.

The configuration should be structured as follows:

mappings:
  - from: ...
    to: ...
    statics:
      - path: /app
        dir: ~/project/dist
        index: index.html

Proxy mode

In proxy mode, requests that start with the path specified in the path property will be handled by the static file handler, unless the requests cannot be matched to any of the files. These unmatched requests will be forwarded and processed either by a mock handler or proxy to a real server.

To configure this mode, simply leave the index property empty:

mappings:
  - from: ...
    to: ...
    statics:
      - path: /app
        dir: ~/project/dist
Clone this wiki locally