-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (26 loc) · 913 Bytes
/
Copy pathserver.js
File metadata and controls
54 lines (26 loc) · 913 Bytes
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
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
const webConfig = require('./config/webConfig.json');
app.use((req, res, next) => {
res.locals.webConfig = webConfig;
next();
});
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
const logger = require('./middleware/logger');
app.use(logger);
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(path.join(__dirname, 'public')));
const apiRouter = require('./routes/api');
app.use('/api', apiRouter);
const viewRouter = require('./routes/views');
app.use('/', viewRouter);
const { errorHandler, notFoundHandler } = require('./middleware/errorHandler');
app.use(notFoundHandler);
app.use(errorHandler);
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});