How to setup URLs for static site with Ruby Rack on Heroku

后端 未结 2 1951
说谎
说谎 2020-12-29 11:27

My site is here.

It used to be a Django-powered blog. However I no longer update it so I just wanted to make it a static HTML site. I wget\'ed it and moved it to Her

相关标签:
2条回答
  • 2020-12-29 11:55

    For now I found the best answer to be:

    use Rack::Static, 
      :urls => ["/media/images", "/media/js", "/media/css"],
      :root => "public"
    
    map "/" do
      run lambda { |env|
      [
        200, 
        {
          'Content-Type'  => 'text/html', 
          'Cache-Control' => 'public, max-age=86400' 
        },
        File.open('public/index.html', File::RDONLY)
      ]
    }
    end
    
    map "/portfolio" do
      run lambda { |env|
      [
        200, 
        {
          'Content-Type'  => 'text/html', 
          'Cache-Control' => 'public, max-age=86400' 
        },
        File.open('public/portfolio/index.html', File::RDONLY)
      ]
    }
    end
    

    And map every URL to its respective file. Tedious, but works. See also the answer to this question regarding URL variables. Couldn't get it to work for me though.

    0 讨论(0)
  • 2020-12-29 12:05

    Why do you need the run statement? Maybe this works for you:

    use Rack::Static, 
      :urls => ["/media/images", "/media/js", "/media/css"],
      :root => "public",
      :index => "index.html",
      :header_rules => [
        [:all, {'Cache-Control' => 'public, max-age=86400'}]
      ]
    
    run lambda{ |env| [ 404, { 'Content-Type'  => 'text/html' }, ['404 - page not found'] ] }
    
    0 讨论(0)
提交回复
热议问题