forked from eidankl/cdstore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (44 loc) · 1.4 KB
/
server.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
var express = require ('express'); //now we have ref to module express
var url = require('url');
var app = express(); //ref to the WS
var CDStock = require('./CD'); //ref to my module
var CD = new CDStock; //new instance from CD
/* ROOT */
/* http://localhost:3000/ */
app.get('/', function(req,res){
res.set('X-header_One', 'app.get');
res.send(" localhost called, CDStock WS ROOT");
});
/* getCD */
/* http://localhost:3000/cd */
app.get('/cd', function(req,res){
var temp = CD.getCD();
res.set('X-header_One', 'app.getCD');
res.json(temp);
});
/* getCDByMonth*/
/* http://localhost:3000/month?Month=April */
app.get('/month', function(req,res) {
var urlPart = url.parse(req.url,true);
var query = urlPart.query;
var temp = CD.getCDByMonth(query.Month);
res.set('X-header_One', 'app.getCDByMonth');
res.json(temp);
});
/* getCDByMonthAndName */
/* http://localhost:3000/monthAndName?Month=June&&Name=John%20Lenon */
app.get('/monthAndName', function(req,res){
var urlObj = url.parse(req.url,true);
var query = urlObj.query;
var temp = CD.getCDByMonthAndName((query.Month),(query.Name));
res.set('X-header_One', 'app.getCDByMonth');
res.json(temp);
})
/* for herouko */
app.listen(process.env.PORT || 3000);
/* module function */
CD.getCD();
CD.getCDByMonth('April');
CD.getCDByMonth('september');
CD.getCDByMonthAndName('April','Arik Ainshtein');
CD.getCDByMonthAndName('April','Arik');