在与 Sinatra 合作了几周后,我终于可以在暂存环境中部署我的应用程序了。在查看了sinatra 配置设置并环顾四周后,我没有找到一种方法来为每个环境创建一个配置文件,因此没有这样做:
require 'sinatra/base'
require 'sinatra/custom_logger'
class MyApp < Sinatra::Base
helpers Sinatra::CustomLogger
configure :development do
logger = MyCustomLogger::Logger.new(param1,
param2,
param3,
paramX)
set :logger, logger
...
end
configure :production do
logger = MyAnotherCustomerLogger.new(param1, param2)
set :logger, logger
end
configure :whatever do
end
# endpoints definition
end
我想得到一些更清洁的东西,比如:
require 'sinatra/base'
require 'environment_config'
class MyApp < Sinatra::Base
register EnvironmentConfig # Not sure how..
...
end
class EnvironmentConfig
configuration :development do
# 10 lines of configuration
end
configuration: production do
# 20 lines of configuration
end
end
在该类/模块中,我们可以为每个环境创建一个文件,也可以拥有一个包含所有不同配置的文件。
那么我的问题是,有没有办法以配置与端点定义不在同一个位置的方式构建 Sinatra 应用程序?事先谢谢你。