forked from bananatron/sinatra-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
62 lines (46 loc) · 1.17 KB
/
app.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'sinatra'
require 'firebase'
require 'json'
require 'sanitize'
require_relative 'helpers' #If you want to keep things elsewhere
#$base_uri = 'https://my-thing.firebaseio.com' #Fill this out!
puts "---\nDeclare your $base_uri!\n---" if !$base_uri #Above this
$fb_root = Firebase::Client.new($base_uri) #Firebase instance
##Configure block for config stuff if you need it
# configure :development do
# set :bind, '0.0.0.0'
# set :port, 3000
# end
##If you need to use sessions
#enable :sessions
#set :session_secret, $cookie_key
############$
## ROUTES #$
##########$
#Before each request, do these things
before do
@fbUrl = $base_uri
end
#Get ROOT
get '/' do
erb :index
end
#Get TIMES w/ Number (/times/3)
get '/times/:num' do
@num = params[:num].to_i
@result = @num*@num
erb :times
end
#Post EXAMPLE (/example)
post '/example' do
#Example post request - access post params like this:
#name = params[:name]
puts "\n !!Hitting post route, receiving #{params} \n\n"
out = "<h2>Ajaxy things are afoot</h2>" #Note unsafe string
return out
#return Sanitize.clean(out) #Clean string would look like this
end
#Error 500
error 500 do
erb :error
end