gpt4 book ai didi

sails.js - 在sails.js 中处理生产/开发/测试配置

转载 作者:行者123 更新时间:2023-12-04 02:36:52 25 4
gpt4 key购买 nike

有谁知道在sails 中处理prod/dev/test 配置切换的最佳方法吗?我真的很喜欢 actionhero.js 如何根据 NODE_ENV 的内容自动加载 config/environment/{env}.js 但我没有看到在风帆中做类似事情的内置方法。我注意到在服务器引导期间,sails 会加载 config/中的任何文件,所以我现在的hacky 解决方案是设置以下内容:

config/
|-- local.js
|-- environment/
|---- production.js
|---- staging.js
|---- development.js
|---- testing.js

然后在每个 {env}.js 文件中,我只是像这样扩展配置:
if (process.env.NODE_ENV === 'production') {
// Enter any environment specific config changes
config.db = {
db_host: foo,
db_port: bar
}
config.otherThing = {
somevar: 'someval'
}

最佳答案

从 Sails 0.10-rc6 开始,这得到了改进,您现在可以添加 env config 中的子文件夹更改不同环境的设置。

所以你可以简单地添加一个文件 /config/env/development.js/config/env/production.js可以覆盖所有必要的设置

https://github.com/balderdashy/sails/pull/1638更多细节。

更改端口和数据库适配器的示例,例如为 production您的环境 production.js :

module.exports = {
port: 80
};

module.exports.models = {

// Your app's default connection.
// i.e. the name of one of your app's connections (see `config/connections.js`)
//
// (defaults to localDiskDb)
connection: 'someMongodbServer'
};

关于sails.js - 在sails.js 中处理生产/开发/测试配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21790465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com