-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.js
26 lines (21 loc) · 836 Bytes
/
node.js
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
var http = require('http')
var hash = require('object-hash')
var url = require('url')
http.createServer(function (request, response) {
let url_parts = url.parse(request.url, true)
// Chrome requests the favicon. Rather than crash, just return nothing.
if(url_parts.query === undefined || url_parts.query.obj_to_hash === undefined) {
return
}
let o = ""
try {
o = JSON.parse(url_parts.query.obj_to_hash)
} catch(e) {
console.warn('Provided obj_to_hash is not valid JSON; defaulting to using it as a string')
o = url_parts.query.obj_to_hash
}
// TODO: accept options from parameters
response.end(hash(o, {respectType: true, unorderedArrays: true, unorderedSets: true}))
}).listen(8081)
// Console should print message indicating it is up.
console.log('Server running at http://127.0.0.1:8081/')