-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.ru
50 lines (39 loc) · 1.01 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
load 'api.rb'
# Sinatra logs are in stdout...
log = File.new("log/sinatra.log", "a+")
# reopen does not works with passenger
#$stdout.reopen(log)
#$stderr.reopen(log)
#run OpenSensor::Application
# Mapping
# -------
# Rest with Rails
#map "/" do
# run OpenSensor::Application
#end
# Anything urls starting with /slim will go to Sinatra
#map "/api" do
# run OpenSensorApi
#end
class SubdomainDispatcher
def initialize
@frontend = OpenSensor::Application
@api = OpenSensorApi.new
end
def call(env)
if subdomain(env) == 'api'
return @api.call(env)
else
return @frontend.call(env)
end
end
private
# If may be more robust to use a 3rd party plugin to extract the subdomain
# e.g ActionDispatch::Http::URL.extract_subdomain(@env['HTTP_HOST'])
def subdomain env
env['HTTP_HOST'].split('.').first
end
end
run SubdomainDispatcher.new