Skip to content

Commit 82b2d00

Browse files
committed
switching from subdomain to namespace for easier api version control
1 parent 6ec50a9 commit 82b2d00

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ RUN bundle install --system
1010
ADD . /app
1111
RUN bundle install --system
1212

13-
ENV VIRTUAL_HOST=api.example.com
14-
1513
EXPOSE 9292
1614

1715
CMD ["bundle", "exec", "rackup"]

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ gem 'puma', '3.4.0'
77
gem 'rack-test'
88
gem 'rake'
99
gem 'sinatra'
10+
gem "sinatra-namespace"
1011
gem 'sinatra-subdomain'
1112
gem 'sinatra-cross_origin'
1213
gem 'test-unit'

Gemfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4+
backports (3.8.0)
45
bson (4.2.2)
56
foreman (0.84.0)
67
thor (~> 0.19.1)
78
json (2.1.0)
89
mongo (2.4.2)
910
bson (>= 4.2.1, < 5.0.0)
11+
multi_json (1.12.1)
1012
mustermann (1.0.0)
1113
power_assert (1.0.2)
1214
puma (3.4.0)
@@ -21,7 +23,16 @@ GEM
2123
rack (~> 2.0)
2224
rack-protection (= 2.0.0)
2325
tilt (~> 2.0)
26+
sinatra-contrib (2.0.0)
27+
backports (>= 2.0)
28+
multi_json
29+
mustermann (~> 1.0)
30+
rack-protection (= 2.0.0)
31+
sinatra (= 2.0.0)
32+
tilt (>= 1.3, < 3)
2433
sinatra-cross_origin (0.4.0)
34+
sinatra-namespace (1.0)
35+
sinatra-contrib
2536
sinatra-subdomain (0.3.0)
2637
sinatra
2738
test-unit (3.2.5)
@@ -41,6 +52,7 @@ DEPENDENCIES
4152
rake
4253
sinatra
4354
sinatra-cross_origin
55+
sinatra-namespace
4456
sinatra-subdomain
4557
test-unit
4658

app.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66

77
require 'bundler/setup'
88
require 'sinatra'
9+
require "sinatra/namespace"
910
require 'sinatra/subdomain'
1011
require 'sinatra/cross_origin'
1112
require 'json'
1213
require 'mongo'
1314

14-
# Allow connections other than localhost
15-
set :bind, '0.0.0.0'
16-
1715
# Uses the modular version of Sinatra
1816
class SpacexAPI < Sinatra::Base
19-
register Sinatra::Subdomain
17+
register Sinatra::Namespace
2018
register Sinatra::CrossOrigin
2119

2220
# Enable CORS
@@ -57,8 +55,8 @@ class SpacexAPI < Sinatra::Base
5755
# redirect request.url.sub('http', 'https') unless request.secure?
5856
# end
5957

60-
# Uses subdomain api.example.com to route traffic
61-
subdomain :api do
58+
# Sets namespace for all following URL's
59+
namespace '/api/v1' do
6260

6361
##########################################
6462
# Basic Info Endpoints

0 commit comments

Comments
 (0)