-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonServer_backup.js
70 lines (57 loc) · 1.22 KB
/
jsonServer_backup.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
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
63
64
65
66
67
68
69
70
var http = require('http');
var url = require('url');
http.createServer(function (request, response) {
var jsonObject;
var jsonString;
var queryData;;
response.writeHead(200, {'Content-Type': 'text/javascript'});
if( url.parse(request.url).pathname == '/data' ){
queryData = url.parse(request.url, true).query;
if (queryData.jsoncallback){
console.log(queryData.jsoncallback);
}
jsonObject = {
"soloToGuess": "solos/RKJF.mp3",
"songs": [{"name":"Master Of puppets", "id": 6001}, {"name":"For Whom the Bell Tolls", "id": 6002}],
"artists": [
{
"name": "",
"id": -1
},
{
"name": "Metallica",
"id": 5001
},
{
"name": "Redd Kross",
"id": 5002
},
{
"name": "Judas Priest",
"id": 5003
},
{
"name": "Motley Crue",
"id": 5004
},
{
"name": "REO Speedwagon",
"id": 5005
},
{
"name": "Iron Maiden",
"id": 5006
}
]
};
jsonString = JSON.stringify(jsonObject);
jsonString = queryData.jsoncallback.concat("(", jsonString, ");");
console.log(jsonString);
response.write(jsonString);
}
else{
response.write('Hello!');
}
response.end();
}).listen(9001);
console.log('9001 Server started');