Obromios
Obromios

Reputation: 16393

running in production mode on local machine accesses heroku

I am trying to run in production mode on my local machine using puma. If I type

rails server -e production

the server starts up with a message

Puma 2.16.0 starting...
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://localhost:3000

When I type into the browser (chrome or safari),

http://localhost:3000

instead of accessing the local server, it goes to the real production site on heroku. I tried clearing the browser cache and it still goes to Heroku. How do I fix this?

Note that if I stop the server, and run in development mode, the browser still goes to Heroku, but if I clear the browser cache, it goes to the local server again.

Upvotes: 1

Views: 1420

Answers (1)

Obromios
Obromios

Reputation: 16393

It turned out that I had the following code in an initializer

MyApp::Application.config.middleware.insert_before(Rack::Runtime, Rack::Rewrite) do
  r301 /.*/, 'http://www.myapp.com$&', if: proc {|rack_env|
    rack_env['SERVER_NAME'] != 'www.myapp.com'
  }
end if Rails.env == 'production'

which was for a redirect for the naked domain. If I turned this off for my local machine, rails s -e production correctly directs to local host.

Upvotes: 1

Related Questions