Universal Environment Configuration
From soya-next-scripts@0.3.0 and later, environment configuration is embedded during runtime. Therefore, every changes made in the configuration will take effect immediately after restarting the server. It's the opposite of the earlier version which is embedded during compile time and need to be rebuilt before the changes took effect.
Creating Configuration Files
Environtment configuration in Soya Next is configured using node-config. To create one, you need to understand how it works first. By default, node-config will read all your configuration files defined in config
directory relative to your Soya Next project root. It will read your configuration files with the following order:
Where
EXT
can beyml
,yaml
,xml
,coffee
,cson
,properties
,json
,json5
,hjson
orjs
depending on the format you prefer,{instance}
is an optional instance name string for Multi-Instance Deployments.{short_hostname}
is your server name up to the first dot, from theHOST
orHOSTNAME
environment variable oros.hostname()
(in that order). For example if your hostname iswww.example.com
then it would loadwww.EXT
.{full_hostname}
is your whole server name, you may use this when{short_hostname}
collides with other machines.{deployment}
is the deployment name, from theNODE_ENV
environment variable.
Please refer to this wiki for the full documentation.
Using Configuration Values
Suppose you have the following configuration at config/default.json
:
You can access the configuration values by looking at the example below.
Please refer to this wiki for the full documentation.
Reserved Configuration Keys
The following are the configurations keys which are reserved:
assetPrefix
assetPrefix
Type:
string
Prefix added to assets. It will fallback to basePath
or basePath.test
.
basePath
basePath
Type:
string
or{ test: string, exclude: string|Array.<string> }
Base URL to which the app paths (assets, pages, static) are prefixed.
defaultLocale
defaultLocale
Type:
string
The default locale used when no locale segment found in the url.
Examples
routes
routes
Type:
Object.<Object>
Define custom routes.
Examples
redirects
redirects
Type:
Object.<Object>
Redirect obsolete pages.
Examples
Redirect static routes
Redirect custom routes
siteLocales
siteLocales
Type:
Array.<string>
All locales which is supported by your app.
Examples
server
server
Type:
Object
Default:
{ "host": "0.0.0.0", "port": 3000 }
For security reasons, the configuration within server
won't get exposed/hydrated to the client. It should not be consumed by the client as well. So if you wanted to consume a secret, it'd be best to store it within server
and ensure it only got consumed by the server.
Examples
Last updated