Skip to content

Latest commit

 

History

History
93 lines (74 loc) · 2.85 KB

app-server-config-options.md

File metadata and controls

93 lines (74 loc) · 2.85 KB

app-server config options

The app-server binary takes the following config options:

  • --config: path of the javascript file exporting the app-server config. Defaults to app-server.config.js
  • --root: root directory to serve. Defaults to build
  • --fallbackAssetPath: absolute path (relative to the root directory) of the asset to use as fallback when requests don't match any other asset. The asset MUST exist. Defaults to /index.html
  • --fallbackStatusCode: status code to use when serving the fallback asset. Defaults to 200
  • --headers: (asset matcher, headers) map specifying which headers to assign to which assets
  • --configuration: JSON configuration object for the static app, i.e. what becomes window.APP_CONFIG
  • --configurationKeyPrefix: Prefix of the environment variables used to generate the configuration for the static app. Defaults to APP_CONFIG_
  • --basePath: static app base path. Defaults to /
  • --port: port to listen on. Defaults to 3000

Options can also be passed via config file, a javascript file exporting an object defining one or more of the above config options. Example:

module.exports = {
  fallbackAssetPath: "/not-found.html",
  fallbackStatusCode: 404
};

Options can also be passed as upper-cased, snake-cased, environment variables prefixed by APP_SERVER_. Eg:

export APP_SERVER_FALLBACK_ASSET_PATH=...
export APP_SERVER_FALLBACK_STATUS_CODE=...

Option sources have the following priority:

  1. command line flags
  2. environment variables
  3. options defined in the config file

Meaning for example that when an option is provided both as a command line flag and as an environment variable, the value provided with the command line flag is used.

App configuration generation

The JSON configuration object that is injected by app-server into the served static app (as the global variable window.APP_CONFIG) is generated by merging:

  • the JSON object passed as the --configuration option
  • a JSON object generated from environment variables using the following algorithm:
    • filter variables whose name doesn't start with the prefix specified by the --configurationKeyPrefix option
    • strip the prefix from the name of the remaining variables
    • create the object using those key-value pairs
  • the following variables automatically added by app-server:
    • BASE_PATH: the base path specified with the --basePath option

Example

Given the --configuration option:

{
  "KEY_0": "OPT_VALUE_0",
  "KEY_1": "OPT_VALUE_1"
}

the --basePath option /, and given the environment:

APP_CONFIG_KEY_1=ENV_VALUE_1
APP_CONFIG_KEY_2=ENV_VALUE_2
NON_PREFIXED_KEY=VALUE

the following window.APP_CONFIG is generated:

window.APP_CONFIG = {
  KEY_0: "OPT_VALUE_0",
  KEY_1: "ENV_VALUE_1",
  KEY_2: "ENV_VALUE_2",
  BASE_PATH: "/"
};