Skip to content

Add default indices to the public folder in sinatra

Notifications You must be signed in to change notification settings

WillRochaThomas/sinatra-index

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sinatra Indices

The problem: you want the path / to give the contents of public/index.html and /foo, to go to public/foo/index.html.

The solution:

require 'rubygems'
require 'sinatra-index'

class MyApp < Sinatra::Base
  register Sinatra::Index
  use_static_index 'index.html'
  
  ... Sinatra routes ...
end

NOTE: static files are given precedence over dynamic routes in sinatra - this library conforms to this e.g. if you have a block like this:

use_static_index 'index.html'

get '/defined' do
    'Hello world!'
end

if a public/defined/index.html file exists, the server will respond with this - not Hello world!. If you wish for your dynamic route to work then move or delete the public/defined/index.html file

About

Add default indices to the public folder in sinatra

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages