如何在开发环境和生产环境中定义不同的变量?

发布于 2025-01-04 16:16:51 字数 148 浏览 1 评论 0原文

比如远程服务器和端口号,来回更改真的很烦人,我注意到有一个

set :environment, :production/:development 

sinatra 的配置选项,但我不知道如何为每种模式设置不同的变量

like the remote server and port number, It's really annoying to change back and forth, I noticed there's a

set :environment, :production/:development 

configuration option for sinatra, but I don't know how to set different variable to each mode

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风尘浪孓 2025-01-11 16:16:51

你可以有这样的东西:

configure :development do
  set :this
end

configure :production do
  set :that
end

you can have something like this:

configure :development do
  set :this
end

configure :production do
  set :that
end
紫﹏色ふ单纯 2025-01-11 16:16:51

如果您的设置很少:

对于经典 Sinatra 应用程序:

port = 4567 if development?
port = 80 if production?

对于模块化 Sinatra 应用程序:

port = 4567 if Sinatra::Base.environment == :development
port = 80 if Sinatra::Base.environment == :production

但如果您有多个与环境相关的设置,则使用上面的三个建议会更干净:

configure :development, :test do
  port = 4567
  url = "https://secure.appname.com"
  ...
end

If your settings are few:

For classic Sinatra apps:

port = 4567 if development?
port = 80 if production?

For modular Sinatra apps:

port = 4567 if Sinatra::Base.environment == :development
port = 80 if Sinatra::Base.environment == :production

But if you have several environment dependent settings, using three's suggestion above is cleaner:

configure :development, :test do
  port = 4567
  url = "https://secure.appname.com"
  ...
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文