forked from thundercomb/poetrydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.rb
42 lines (34 loc) · 895 Bytes
/
web.rb
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
require 'sinatra'
require 'mongo'
require 'json'
include Mongo
class Web < Sinatra::Base
configure do
mongo_uri = ENV['MONGODB_URI']
db_username = ENV['MONGODB_USER']
db_password = ENV['MONGODB_PASS']
db_name = mongo_uri[%r{/([^/\?]+)(\?|$)}, 1]
client = Mongo::Client.new(mongo_uri, :database => db_name, :user => db_username, :password => db_password)
db = client.database
set :root, File.dirname(__FILE__)
set :public_folder, './public'
set :mongo_client, client
set :mongo_db, db
set :poetry_coll, db.collection("poetry")
end
def json_status(code, reason)
status code
{
:status => code,
:reason => reason
}.to_json
end
after do
response.headers['Access-Control-Allow-Origin'] = '*'
end
get '/' do
redirect '/index.html'
end
end
require_relative 'helpers/init'
require_relative 'routes/init'