简体   繁体   中英

How to configure a sinatra rack app to use figaro

I saw this post and think something is missing or a change in version. I have a very simple rack app using figaro -- hosted with Heroku. Currently, Im on local machine.

I now need to use ENV .

My app structure:

APP
 |_ config/
 |_ public/
 |_ views/
 |_ config.ru
 |_ app.rb
 |_ other-files

Inside config/application.yml

SOME_KEY: some-value

Inside config.ru

require './app.rb'
run MyApp.run!

This the part this gives the error. Inside app.rb:

require  File.dirname(__FILE__) + '/config/application.yml'

[...]

This is the same line as in the link above. I get

cannot load such file /config/application.yml

In app.rb , I need to be able to do ENV['SOME_KEY']

You can't just require a yaml file as it is not ruby. Yaml is a file structure that is not ruby specific. Figaro was also written to be used with Ruby on Rails, not Sinatra. You can probably figure out a way to make it work, but it's not as easy as just loading a yaml config file.

See this post for some ideas of how you might accomplish what you're trying to do. Here is a forked version of the gem which might work for you.

https://github.com/laserlemon/figaro/pull/229

I've done this before in a standalone app as follows:

Figaro.application = Figaro::Application.new(
  environment: 'production',
  path: File.expand_path("config/application.yml")
)
Figaro.load

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM