【问题标题】:Why does sails.js ignore /config/env/production.js and use process.env.PORT instead?为什么sails.js 忽略/config/env/production.js 而使用process.env.PORT?
【发布时间】:2016-01-13 13:30:00
【问题描述】:

我已在 /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
--------------------------------------------------------

【问题讨论】:

  • 您是否更改了 config/local.js 上的端口?因为如果是这种情况,那就是这个人使用
  • 这个环境下没有config/local.js文件。
  • 也许您的系统中有一个端口定义为 8000 ?尝试删除它,因为sails 采用第一个环境变量。就像你说的,如果你将它设置为 8080,它就可以工作,所以它可能首先定义为 8000。还尝试使用sails lift --prod 启动风帆以查看是否使用了女巫端口
  • 是的,你是对的;我花了一段时间才找到设置环境变量的文件。我尝试取消设置,它马上回来了。如果您想在此处添加答案,我很乐意选择它(如果您想要业力)。
  • 很酷,如果它是固定的 :) 不管业力如何 ^^ 很高兴提供帮助。

标签: javascript environment-variables sails.js port environment


【解决方案1】:

原来在父目录中有一个 .ENV 文件会自动设置端口环境变量(即使我取消设置它)。我想在这种情况下,sails 尊重环境变量而不是 /config/production.js 是有意义的。

【讨论】:

    猜你喜欢
    • 2019-07-27
    • 2021-03-11
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2021-09-18
    相关资源
    最近更新 更多