This repository was archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
76 lines (62 loc) · 2.64 KB
/
server.js
File metadata and controls
76 lines (62 loc) · 2.64 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* This file is the entry point of this Express Server.
* It includes setups, configs and router.
*
* Run by: node server.js
*
* @version: 1.0.0
* @author: Benjamin Thomas Schwertfeger (2022)
* @email development@b-schwertfeger.de
* @github https://github.com/ProjectPepperHSB/NodeJS_Server4Pepper
**/
/* * * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * * *
* * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * *
* * * -----> I M P O R T S <----- ----- ----- */
const
express = require('express'),
http = require('http'),
path = require('path'),
cookieParser = require('cookie-parser'),
routes = require('./routes');
const {
PORT,
URL
} = process.env.NODE_ENV == 'PROD' ? require('./config').PRODUCTION : require('./config').DEVELOPMENT;
/* * * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * * *
* * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * *
* * * -----> G E N E R A L - S E T U P <----- ----- ----- */
const app = express()
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
app.use(cookieParser());
app.set('view engine', 'ejs');
app.engine('ejs', require('ejs').__express);
app.set('views', [
`${__dirname}/views`, `${__dirname}/views/includes`
]);
app.use('/static', express.static(path.join(__dirname, 'static'))); // lokal geht das, aber auf dem hopper nicht, daher gibt es 'routes/fileserver.js'
app.use(routes);
/* * * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * * *
* * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * *
* * * -----> R O U T E S <----- ----- ----- */
app.get('/docker-hbv-kms-http/', (req, res) => {
res.render('', {
environment: (process.env.NODE_ENV === 'PROD') ? 'Production' : 'Developement',
});
});
// must be at the end to catch all incorrect requests
function errorHandler(req, res, next) {
res.status(404).end();
}
app.use(errorHandler);
/* * * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * * *
* * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * *
* * * -----> S T A R T <----- ----- ----- */
http.createServer(app).listen(PORT, () => {
console.log(`Listening on ${URL}`)
})
/* * * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * * *
* * * ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- * * *
* * * -----> E OF <----- ----- ----- */