为什么 sails.js 忽略 /config/env/production.js 而使用 process.env.PORT 代替?
Why does sails.js ignore /config/env/production.js and use process.env.PORT instead?
我在 /config/env/production.js 中将端口设置为 8080,并将环境变量 NODE_ENV 设置为生产。然而,当我扬帆起航时,我只让它在 8000 端口启动。最终我意识到我可以设置端口环境变量并获得正确的结果,但我更愿意使用普通的配置文件。我没有 local.js 配置文件,所以不会覆盖。我做错了什么?
[15:12:50] nodejs @ myserver : /apps/myapi/
$ cat config/env/production.js
/**
* Production environment settings
*
* This file can include shared settings for a production environment,
* such as API keys or remote database passwords. If you're using
* a version control solution for your Sails app, this file will
* be committed to your repository unless you add it to your .gitignore
* file. If your repository will be publicly viewable, don't add
* any private information to this file!
*
*/
module.exports = {
/***************************************************************************
* Set the default database connection for models in the production *
* environment (see config/connections.js and config/models.js ) *
***************************************************************************/
// models: {
// connection: 'someMysqlServer'
// },
/***************************************************************************
* Set the port in the production environment to 80 *
***************************************************************************/
port: 8080,
/***************************************************************************
* Set the log level in production environment to "silent" *
***************************************************************************/
// log: {
// level: "silent"
// }
};
[15:13:09] nodejs @ myserver : /apps/myapi/
$ sails lift
Starting app...
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
.-..-.
Sails <| .-..-.
v0.11.2 |\
/|.\
/ || \
,' |' \
.-'.-==|/_--'
`--'-------'
__---___--___---___--___---___--___
____---___--___---___--___---___--___-__
Server lifted in `/apps/myapi`
To see your app, visit http://localhost:8000
To shut down Sails, press <CTRL> + C at any time.
--------------------------------------------------------
:: Thu Oct 15 2015 15:13:21 GMT+0800 (HKT)
Environment : production
Port : 8000
--------------------------------------------------------
^C
[15:15:20] nodejs @ myserver : /apps/myapi/
$ export PORT=8080
[15:15:41] nodejs @ myserver : /apps/myapi/
$ sails lift
Starting app...
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
.-..-.
Sails <| .-..-.
v0.11.2 |\
/|.\
/ || \
,' |' \
.-'.-==|/_--'
`--'-------'
__---___--___---___--___---___--___
____---___--___---___--___---___--___-__
Server lifted in `/apps/myapi`
To see your app, visit http://localhost:8080
To shut down Sails, press <CTRL> + C at any time.
--------------------------------------------------------
:: Thu Oct 15 2015 15:15:48 GMT+0800 (HKT)
Environment : production
Port : 8080
--------------------------------------------------------
原来父目录中有一个 .ENV 文件自动设置端口环境变量(即使我取消设置)。我想在这种情况下,sails 在 /config/production.js 上尊重环境变量是有意义的。
我在 /config/env/production.js 中将端口设置为 8080,并将环境变量 NODE_ENV 设置为生产。然而,当我扬帆起航时,我只让它在 8000 端口启动。最终我意识到我可以设置端口环境变量并获得正确的结果,但我更愿意使用普通的配置文件。我没有 local.js 配置文件,所以不会覆盖。我做错了什么?
[15:12:50] nodejs @ myserver : /apps/myapi/
$ cat config/env/production.js
/**
* Production environment settings
*
* This file can include shared settings for a production environment,
* such as API keys or remote database passwords. If you're using
* a version control solution for your Sails app, this file will
* be committed to your repository unless you add it to your .gitignore
* file. If your repository will be publicly viewable, don't add
* any private information to this file!
*
*/
module.exports = {
/***************************************************************************
* Set the default database connection for models in the production *
* environment (see config/connections.js and config/models.js ) *
***************************************************************************/
// models: {
// connection: 'someMysqlServer'
// },
/***************************************************************************
* Set the port in the production environment to 80 *
***************************************************************************/
port: 8080,
/***************************************************************************
* Set the log level in production environment to "silent" *
***************************************************************************/
// log: {
// level: "silent"
// }
};
[15:13:09] nodejs @ myserver : /apps/myapi/
$ sails lift
Starting app...
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
.-..-.
Sails <| .-..-.
v0.11.2 |\
/|.\
/ || \
,' |' \
.-'.-==|/_--'
`--'-------'
__---___--___---___--___---___--___
____---___--___---___--___---___--___-__
Server lifted in `/apps/myapi`
To see your app, visit http://localhost:8000
To shut down Sails, press <CTRL> + C at any time.
--------------------------------------------------------
:: Thu Oct 15 2015 15:13:21 GMT+0800 (HKT)
Environment : production
Port : 8000
--------------------------------------------------------
^C
[15:15:20] nodejs @ myserver : /apps/myapi/
$ export PORT=8080
[15:15:41] nodejs @ myserver : /apps/myapi/
$ sails lift
Starting app...
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
.-..-.
Sails <| .-..-.
v0.11.2 |\
/|.\
/ || \
,' |' \
.-'.-==|/_--'
`--'-------'
__---___--___---___--___---___--___
____---___--___---___--___---___--___-__
Server lifted in `/apps/myapi`
To see your app, visit http://localhost:8080
To shut down Sails, press <CTRL> + C at any time.
--------------------------------------------------------
:: Thu Oct 15 2015 15:15:48 GMT+0800 (HKT)
Environment : production
Port : 8080
--------------------------------------------------------
原来父目录中有一个 .ENV 文件自动设置端口环境变量(即使我取消设置)。我想在这种情况下,sails 在 /config/production.js 上尊重环境变量是有意义的。