Skip to content

Commit

Permalink
fixing paths
Browse files Browse the repository at this point in the history
  • Loading branch information
slim2000 committed Oct 22, 2012
1 parent 73a9beb commit e2a7b7b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.rb
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'
68 changes: 68 additions & 0 deletions notify.rb
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

0 comments on commit e2a7b7b

Please sign in to comment.