bundle exec rackup config.ru
Last active
May 26, 2023 15:00
-
-
Save stereobooster/985cdbd494688e7b50551d2d62aaae1b to your computer and use it in GitHub Desktop.
Sinatra namespace example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
class Application < Sinatra::Base | |
get "/" do | |
"Hello World!" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'root' | |
run Root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
source "https://rubygems.org" | |
gem "sinatra", "~> 1.4" | |
gem "thin" | |
gem "sinatra-router" | |
gem "sinatra-contrib" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
backports (3.8.0) | |
daemons (1.2.4) | |
eventmachine (1.2.3) | |
multi_json (1.12.1) | |
rack (1.6.8) | |
rack-protection (1.5.3) | |
rack | |
rack-test (0.6.3) | |
rack (>= 1.0) | |
sinatra (1.4.8) | |
rack (~> 1.5) | |
rack-protection (~> 1.4) | |
tilt (>= 1.3, < 3) | |
sinatra-contrib (1.4.7) | |
backports (>= 2.0) | |
multi_json | |
rack-protection | |
rack-test | |
sinatra (~> 1.4.0) | |
tilt (>= 1.3, < 3) | |
sinatra-router (0.2.4) | |
sinatra (>= 1.4, < 3.0) | |
thin (1.7.0) | |
daemons (~> 1.0, >= 1.0.9) | |
eventmachine (~> 1.0, >= 1.0.4) | |
rack (>= 1, < 3) | |
tilt (2.0.7) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
sinatra (~> 1.4) | |
sinatra-contrib | |
sinatra-router | |
thin | |
BUNDLED WITH | |
1.14.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'sinatra/namespace' | |
class NamespaceApp1 < Sinatra::Base | |
register Sinatra::Namespace | |
namespace "/v1" do | |
get "/" do | |
"Hello World!" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
require 'sinatra/namespace' | |
class NamespaceApp2 < Sinatra::Base | |
register Sinatra::Namespace | |
namespace "/v2" do | |
get "/" do | |
"Hello World!" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'application' | |
require_relative 'namespace_app1' | |
require_relative 'namespace_app2' | |
require 'sinatra/router' | |
require 'sinatra/base' | |
class Root < ::Sinatra::Base | |
use ::Sinatra::Router do | |
mount NamespaceApp1 | |
mount NamespaceApp2 | |
mount Application | |
end | |
end | |
# Also can do it this way | |
# Root = Sinatra::Router.new do | |
# mount NamespaceApp1 | |
# mount NamespaceApp2 | |
# mount Application | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment