1
我在/config/env/production.js中將端口設置爲8080,並將環境變量NODE_ENV設置爲生產。然而,當我舉起帆時,我只能在端口8000上啓動它。最終我意識到我可以設置端口環境變量並獲得正確的結果,但我更願意使用正常的配置文件。我沒有local.js配置文件,所以這不是覆蓋。我究竟做錯了什麼?爲什麼sails.js會忽略/config/env/production.js並改用process.env.PORT?
[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
--------------------------------------------------------
你是否改變了你的config/local.js端口?因爲這是一個誰使用,如果是這種情況 – jaumard
在這個環境中沒有config/local.js文件。 – carpiediem
也許你的系統中有一個PORT定義爲8000?嘗試刪除它導致風帆採取第一個環境變量。就像你說的,如果你將它設置爲8080,那麼它可能會工作,所以也許它首先定義爲8000.另外,嘗試使用帆升降機啓動帆 - 生產使用女巫端口的產品 – jaumard