Serving static files with Sinatra

后端 未结 14 1749
渐次进展
渐次进展 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

    You could just host them from the public folder and they do not need routes.

    .
    -- myapp.rb
    `-- public
        |-- application.css
        |-- application.js
        |-- index.html
        `-- jquery.js
    

    In the myapp.rb

    set :public_folder, 'public'
    
    get "/" do
      redirect '/index.html'
    end
    

    Link to some sub folder in public

    set :public_folder, 'public'
    get "/" do
      redirect '/subfolder/index.html' 
    end
    

    Everything in ./public is accessible from '/whatever/bla.html

    Example :
    ./public/stylesheets/screen.css
    Will be accessible via '/stylesheets/screen.css' no route required

    0 讨论(0)
  • 2020-11-29 17:00

    Add below line in main rb file

    set :public_folder, 'public'
    
    0 讨论(0)
提交回复
热议问题