Upgrade doc to use env var and js config files

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-04-21 15:42:33 +02:00
parent 3d071f5869
commit 2e31afe6dd
8 changed files with 38 additions and 33 deletions

View File

@ -275,10 +275,6 @@ You can access the config of the current environment through `strapi.config.curr
}
```
::: tip
Please refer to the [dynamic configurations section](#dynamic-configurations) to use global environment variable to configure the databases.
:::
#### MLab Example
**Path —** `./config/environments/**/database.json`.

View File

@ -111,14 +111,14 @@ env.date('NAME', new Date());
## Environments
WHat if you need to specific static configuration sfor specific environments anv using environement variables becomes tedious ?
What if you need to specific static configurations for specific environments and using environement variables becomes tedious ?
Strapi configurations can also be create per envrionement in `./config/env/{env}/{filename}`. These configurations will be merged into the base ones define in the `./config` folder.
Strapi configurations can also be created per envrionement in `./config/env/{env}/{filename}`. These configurations will be merged into the base ones defined in the `./config` folder.
The envrionement is based on the `NODE_ENV` envrionement variable (defaults to `development`).
When starting strapi with `NODE_ENV` = `production` it will load the configuration from `./config/*` and `./config/env/production/*`.Everything defined in the production config will override the default config.
When starting strapi with `NODE_ENV=production` it will load the configuration from `./config/*` and `./config/env/production/*`. Everything defined in the production config will override the default config.
In combination with envrionement variables the becomes really powerfull:
In combination with environment variables this pattern becomes really powerfull:
**Example**

View File

@ -90,30 +90,29 @@ Additional guides for optional software additions that compliment or improve the
### 1. Configure
Update the `production` settings with the IP or domain name where the project will be running.
We always recommend you use envrionement variables to configure your application based on the envrionement. Here is an example:
**Path —** `./config/environments/production/server.json`.
**Path —** `./config/server.js`.
```js
{
"host": "0.0.0.0", // IP, localhost, or 0.0.0.0
"port": 1337
}
module.exports = ({ env }) => ({
host: env('APP_HOST', '0.0.0.0'),
port: env.int('NODE_PORT', 1337),
});
```
In case your database is not running on the same server, make sure that the environment of your production
database (`./config/environments/production/database.json`) is set properly.
Then you can create a `.env` file or directly use the deployment platform you use to set envrionement variables:
If you are passing a number of configuration item values via environment variables, which is always encouraged for production environment, read the section for [Dynamic Configuration](../concepts/configurations.md#dynamic-configurations). Here is an example:
**Path —** `.env`.
**Path —** `./config/environments/production/server.json`.
```js
{
"host": "${process.env.APP_HOST || '0.0.0.0'}",
"port": "${process.env.NODE_PORT || 1337}"
}
```
APP_HOST=10.0.0.1
NODE_PORT=1338
```
::: tip
To learn more about configuration you can read the documentation [here](../concepts/configurations.md)
:::
### 2. Launch the server

View File

@ -346,7 +346,7 @@ The above configuration will create a database called `strapi`, the _default dat
:::
::: danger WARNING
We recommend replacing sensitive (eg. "URI string" above) information in your database.json files before uploading your project to a public repository such as GitHub. For more information about using environment variables, please read [dynamic configurations](../concepts/configurations.md#dynamic-configurations).
We recommend replacing sensitive (eg. "URI string" above) information in your database configuration files before uploading your project to a public repository such as GitHub. For more information about using environment variables, please read [configurations](../concepts/configurations.md).
:::

View File

@ -742,8 +742,18 @@ You can update these templates under **Plugins** > **Roles & Permissions** > **E
## Security configuration
JWT tokens can be verified and trusted because the information is digitally signed. To sign a token a _secret_ is required. By default Strapi generates one that is stored in `./your-app/extensions/users-permissions/config/jwt.json`. This is useful during development but for security reasons it is **recommended** to set a custom token via an environment variable `JWT_SECRET` when deploying to production. It is also possible to modify `jwt.json` file to accept `JWT_TOKEN` automatically by doing following ([docs](https://strapi.io/documentation/3.0.0-beta.x/concepts/configurations.html#dynamic-configurations)).
JWT tokens can be verified and trusted because the information is digitally signed. To sign a token a _secret_ is required. By default Strapi generates one that is stored in `./extensions/users-permissions/config/jwt.js`. This is useful during development but for security reasons it is **recommended** to set a custom token via an environment variable `JWT_SECRET` when deploying to production.
By default you can set a `JWT_SECRET` envrionement variable and it will be used as secret. If you want to use another variable you can update the configuration file.
**Path -** `./extensions/users-permissions/config/jwt.js`.
```js
module.exports = {
jwtSecret: process.env.SOME_ENV_VAR,
};
```
"jwtSecret": "${process.env.JWT_SECRET}"
```
::: tip
You can learn more on configuration in the documentation [here](../concepts/configurations.md)
:::

View File

@ -0,0 +1,3 @@
module.exports = {
jwtSecret: process.env.JWT_SECRET || 'c98f7e9c-dc1d-4ee1-a380-53c3a7125a7e',
};

View File

@ -1,3 +0,0 @@
{
"jwtSecret": "bb26b371-8957-434c-a313-f35dd6b1813c"
}

View File

@ -172,8 +172,8 @@ module.exports = async () => {
await strapi.fs.writePluginFile(
'users-permissions',
'config/jwt.json',
JSON.stringify({ jwtSecret }, null, 2)
'config/jwt.js',
`module.exports = {\n jwtSecret: process.env.JWT_SECRET || '${jwtSecret}'\n};`
);
strapi.reload.isWatching = true;