-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
require 'pusher' | |||
|
|||
Pusher.app_id = '30086' | |||
Pusher.key = 'c098fd0ea035d82a56b5' | |||
Pusher.secret = 'ae8639f60016286c5179' |
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,68 @@ | |||
require 'config.rb' | |||
|
|||
require 'sinatra' | |||
require 'pusher' | |||
require 'json' | |||
|
|||
include Rack::Utils | |||
|
|||
set :public_folder, 'examples/' | |||
|
|||
get '/' do | |||
send_file('examples/index.html') | |||
end | |||
|
|||
get '/notify' do | |||
|
|||
message = params[:message] | |||
|
|||
if( !message ) | |||
status 400 | |||
body 'message must be provided' | |||
end | |||
|
|||
message = sanitise_input(message) | |||
data = {'message' => message} | |||
response = Pusher['my_notifications'].trigger('notification', data) | |||
|
|||
result = {'activity' => data, 'pusherResponse' => response} | |||
|
|||
status 200 | |||
headers \ | |||
'Cache-Control' => 'no-cache, must-revalidate', | |||
'Content-Type' => 'application/json' | |||
|
|||
body result.to_json | |||
end | |||
|
|||
get '/src/*' do | |||
path = params[:splat].join() | |||
path = path.gsub(/(\.\.)|~/, '') # remove ../ and ~ | |||
path = 'src/' + path | |||
type = path[path.rindex('.')+1, path.length] | |||
puts('getting: ' + path + ' type: ' + type) | |||
if(File.exists?(path)) | |||
status 200 | |||
headers \ | |||
'Cache-Control' => 'no-cache, must-revalidate', | |||
'Content-Type' => get_content_type(type) | |||
File.read(path) | |||
else | |||
status 404 | |||
end | |||
end | |||
|
|||
def get_content_type(type) | |||
case type | |||
when "css" | |||
return 'text/css' | |||
when "js" | |||
return 'text/javascript' | |||
else | |||
return 'text/plain' | |||
end | |||
end | |||
|
|||
def sanitise_input(message) | |||
return escape_html(message).slice(0, 300) | |||
end |