Serving static files with Sinatra

后端 未结 14 1797
渐次进展
渐次进展 2020-11-29 16:38

I have one page website only using HTML, CSS and JavaScript. I want to deploy the app to Heroku, but I cannot find a way to do it. I am now trying to make the app working wi

14条回答
  •  甜味超标
    2020-11-29 16:59

    Without any additional configuration, Sinatra will serve assets in public. For the empty route, you'll want to render the index document.

    require 'rubygems'
    require 'sinatra'
    
    get '/' do
      File.read(File.join('public', 'index.html'))
    end
    

    Routes should return a String which become the HTTP response body. File.read opens a file, reads the file, closes the file and returns a String.

提交回复
热议问题