Skip to content

Instantly share code, notes, and snippets.

@tadruj
Created February 24, 2012 18:16
Show Gist options
  • Save tadruj/1902528 to your computer and use it in GitHub Desktop.
Save tadruj/1902528 to your computer and use it in GitHub Desktop.
# This is API module, mapped under /api
require 'sinatra/base'
module My
class API < Sinatra::Base
get '/' do
'Happy API'
end
end
end
# This is main app module, mapped under /, where I would like to define additional route in separate file 'fruit.rb' and loading it with load
require 'sinatra/base'
module My
class App < Sinatra::Base
get '/' do
'Happy App'
end
load './fruit.rb'
end
end
# I run this with `shotgun -p 5000 app.ru` environment being `RACK_ENV=development`
require 'sinatra'
require './app' # the file with My::App class
require './api' # the file with My::API class
disable :run
map '/' do
run My::App
end
map '/api' do
run My::API
end
# This gets loaded with load './fruit.rb'
get '/fruit' do
'Happy Fruit'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment