-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (54 loc) · 1.67 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
// Module imports
import express from 'express';
import layout from 'express-ejs-layouts';
import { createRequire } from 'module';
import swaggerJSDoc from 'swagger-jsdoc';
import swaggerUi from 'swagger-ui-express';
const require = createRequire(import.meta.url);
// Import configs
const { port, ipAddress } = require('./config.json');
// Route imports
import indexRoute from './routes/index.js';
import apiRoute from './routes/api.js';
const PORT = process.env.PORT || port;
const app = express();
// Express options
app.set('view engine', 'ejs');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'System Information API',
version: '0.1.0',
description:
'A simple web app to monitor and manager a server',
license: {
name: 'GNU AGPLv3',
url: 'https://www.gnu.org/licenses/agpl-3.0.de.html',
},
contact: {
name: 'Mauritz Funke',
url: 'https://mauritz-funke.de',
email: '[email protected]',
},
},
servers: [
{
url: 'http://' + ipAddress + ':' + PORT + '/api/',
},
],
},
apis: ['./api/*.js'],
};
const specs = swaggerJSDoc(options);
// Set up routes
app.use('/api', apiRoute);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs, {explorer: true}))
app.use('/static', express.static('./static'));
app.use(layout);
app.set('layout', 'index/layout/layout');
app.use('/', indexRoute);
app.listen(PORT, (err) => {
if (err) throw err;
else console.log(`Server is now running on port ${PORT}`);
});