-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.js.coffee
57 lines (48 loc) · 1.48 KB
/
node.js.coffee
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
# Load the http module to create an http server.
HOST = 'https://api.wrapp.com'
http = require 'http'
https = require 'https'
port = 8080
server = http.createServer (request, response) ->
console.log 'hit: ' + request.url
if not overrideInput(request.url, response)
https.get(HOST + request.url, (res) =>
response.writeHead res.statusCode, res.headers
output = ''
res.on 'data', (d) =>
output += d
res.on 'end', =>
response.end output
).on('error', (e) =>
console.log e
)
else
response.writeHead 200, { 'Content-Type': 'text/plain' }
server.listen port
console.log "Server running at http://127.0.0.1:#{port}/"
overrideInput = (url, response) ->
if url.indexOf('/users/me/news') != -1
response.end JSON.stringify(news)
return true
false
news =
status: 'ok'
news: [
{
gift_id : 'r3X7S1PY'
image : 'http://graph.facebook.com/540915851/picture'
uri : 'wrappcorp:///gifts/r3X7S1PY'
create_time : '2014-03-20T19:48:56+0000'
message : 'You wrapped a gift for Mikael A.'
type : 'notification'
id : 13
}
{
gift_id : '7hgDHsSX'
image : 'http://graph.facebook.com/598632743/picture'
create_time : '2014-03-19T17:05:27+0000'
message : 'C\u00e9sar P wrapped a gift for Cesar.'
type : 'notification'
id : 11
}
]