-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
27 lines (20 loc) · 829 Bytes
/
controller.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
const http = require('http');
module.exports = http.createServer((req, res) => {
const service = require('./service.js');
const baseUrl = 'http://' + req.headers.host + '/';
const reqUrl = new URL(req.url, baseUrl);
if(reqUrl.pathname === '/add' && req.method === 'POST') {
console.log('Request-Type: ' + req.method +
' Endpoint: ' + reqUrl.pathname);
service.addJSONNumbers(req, res);
}else if(reqUrl.pathname === '/add' && req.method === 'GET') {
console.log('Request-Type: ' + req.method +
' Endpoint: ' + reqUrl.pathname);
service.addQueryNumbers(req, res);
}else {
console.log('Request Type:' +
req.method + ' Invalid Endpoint: ' +
reqUrl.pathname);
service.invalidRequest(req, res);
}
})