-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
103 lines (81 loc) · 2.8 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var express = require('express');
var bodyParser = require('body-parser');
var config = require('./config/config');
var homeControl = require('./controller/homeControl');
var forecastControl = require('./controller/forecastControl');
var userControl = require('./controller/userControl');
var app = express();
var resp = function (res, data, code, next) {
res.status(code).json(data);
return next();
};
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, Origin, Content-Type, Accept');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
});
app.listen(config.init_port);
console.log("Application is listening on port ", config.init_port);
app.post('/beranda/add', function (req, res, next) {
var body = req.body;
homeControl.addAQI(body, function (response, code) {
resp(res, response, code, next)
})
});
app.get('/beranda/:id', function (req, res, next) {
var param = req.params;
homeControl.getAQI(param, function (response, code) {
resp(res, response, code, next)
})
});
app.get('/beranda/aqi/:id', function (req, res, next) {
var param = req.params;
homeControl.getAQIs(param, function (response, code) {
resp(res, response, code, next)
})
});
app.get('/forecast/:day/:month/:year/:places', function (req, res, next) {
var param = req.params;
forecastControl.getForecast(param, function (response, code) {
resp(res, response, code, next)
})
});
app.post('/forecast/add', function (req, res, next) {
var body = req.body;
forecastControl.addForecast(body, function (response, code) {
resp(res, response, code, next)
})
});
app.post('/user/register', function (req, res, next) {
var body = req.body;
userControl.addUser(body, function (response, code) {
resp(res, response, code, next)
})
});
app.get('/user/:phone', function (req, res, next) {
var param = req.params;
userControl.getUser(param, function (response, code) {
resp(res, response, code, next)
})
});
app.post('/user/login/', function (req, res, next) {
var body = req.body;
userControl.loginUser(body, function (response, code) {
resp(res, response, code, next)
})
});
app.get('/user/verify/:phone', function (req, res, next) {
var param = req.params;
userControl.verifyUser(param, function (response, code) {
resp(res, response, code, next)
})
});
app.get('/user/delete/:number', function (req, res, next) {
var param = req.params;
userControl.deleteUser(param, function (response, code) {
resp(res, response, code, next)
})
});