[英]Why does sails.js ignore /config/env/production.js and use process.env.PORT instead?
我已在/config/env/production.js中将端口设置为8080,并将环境变量NODE_ENV设置为production。 但是,当我扬帆起航时,我只能在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文件,该文件会自动设置端口环境变量(即使我未设置它)。 我想在这种情况下,让帆尊重/config/production.js上的环境变量是有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.