Linus
Linus

Reputation: 2819

Rack app, redirect everything to root

I just deployed a static page to Heroku as a static rack app. My config.ru:

use Rack::Static, 
  :urls => ["/stylesheets", "/images"],
  :root => "public",
  :index => "public/index.html"

run lambda { |env|
  [
    200, 
    {
      'Content-Type'  => 'text/html', 
      'Cache-Control' => 'public, max-age=86400' 
    },
    File.open('public/index.html', File::RDONLY)
  ]
}

Now I want to redirect all request to this static index.html file. Any ideas how to achieve this?

Upvotes: 1

Views: 906

Answers (2)

Linus
Linus

Reputation: 2819

It actually worked from the beginning. I just had to adjust the paths to my images and CSS files.

Upvotes: 1

moritz
moritz

Reputation: 25767

If you remove the call to "use" the middleware Rack::Static, all requests will render index.html. Although you probably have to write

File.open('public/index.html').read

instead of

File.open('public/index.html', File::RDONLY)

Upvotes: 0

Related Questions