-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.js
More file actions
executable file
·52 lines (46 loc) · 1.59 KB
/
Server.js
File metadata and controls
executable file
·52 lines (46 loc) · 1.59 KB
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
//'node Server.js'
//This is the server file, it will handle all requests and responses
//Server configuration
const port = 8082;// 80, 443, 8082 nginx
const express = require('express');
const app = express();
const logs = require('./modules/logger');
app.listen(port, () => {
try {
logs.initalize();//initalize logger
logs.info('Server starting');//log server start
logs.info('Running on port ', port);
logs.info('Process ID: ', process.pid);
logs.info('Process path: ', process.cwd());
} catch (error) {
logs.error('Catastrophy on server start: ', error);
}
})//Listen for requests, this starts the server
//bind root path to /www folder
app.use(express.static('www')).listen(() => {
});
app.get('/get/test', (req, res) => {//test get
try {
logs.info('test get');
req.on('data', function (data) {
logs.info('got: ', data);
res.end(JSON.stringify({ testget: "test get data received" }));
});
//res.writeHead(200, { 'Content-type': 'application/json' });
res.send(JSON.stringify({ test: 'test get is okay' }));
} catch (error) {
logs.error('Catastrophy on test get: ', err);
}
});
app.post('/post/test', (req, res) => {//test post
//receive more data than a get
try {
logs.info('test post to server');
req.on('data', function (data) {
logs.info('Posted : ', JSON.parse(data));
res.end(JSON.stringify({ test: "test post received" }));
});
} catch (error) {
logs.error('Catastrophy on test post: ', err);
}
});