简体   繁体   中英

get server url in rake task

Is there any way I can get the url of the application inside a rake task? I'm running heroku, so maybe there is a way I can get hold of the appname?

I was able to do the following in my Rakefile:

task(:foo => :environment) do
  puts ENV['APP_NAME']
end

and it successfully returned Heroku's application name, my_foo_app. when I ran the command:

heroku rake foo --app my_foo_app

You can just set a config variable with the app URL using

heroku config:add APP_URL=http://myapp.com

Then you can get the value inside your rake task (or anywhere in your app) using ENV['APP_URL']

Documentation: http://docs.heroku.com/config-vars

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