-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.js
55 lines (44 loc) · 1.91 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
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, './.env') });
const config = require('config');
const express = require('express');
const http = require('http');
require('./database');
const logger = require('./modules/Logger');
const app = express();
const port = config.get('webPort');
// Trust all proxies, this is required for `req.ip` to work properly with Cloudflare.
app.set('trust proxy', true);
// Parse the HTTP message body for input parameters.
// Any parameters that are found will be added to `req.body`.
app.use(require('./middlewares/bodyParserJson'));
app.use(require('./middlewares/bodyParserUrlencoded'));
// Configure cross-origin resource sharing (CORS).
// Allows CORS to from all origins.
app.use(require('./middlewares/cors'));
// Load all API routes.
const testLinkRoute = require('./routes/testLinkRoute');
const testIdRoute = require('./routes/testIdRoute');
const testNameRoute = require('./routes/testNameRoute');
const itemRoute = require('./routes/itemRoute');
const paintkitRoute = require('./routes/paintkitRoute');
const skinRoute = require('./routes/skinRoute');
// Register the API routes.
app.use('/inspect-links', testLinkRoute);
app.use('/tests/link', testLinkRoute);
app.use('/tests/id', testIdRoute);
app.use('/tests/name', testNameRoute);
app.use('/items', itemRoute);
app.use('/paintkits', paintkitRoute);
app.use('/skins', skinRoute);
// Use a 404 handler for all requests where no Express route was found.
app.use('*', require('./middlewares/notFoundHandler'));
// The global error handler.
app.use(require('./middlewares/errorHandler'));
// Create a new HTTP server instance and attach our Express app as the request listener.
const server = http.createServer(app);
// Start the HTTP server and listen for connections.
server.listen(port, '0.0.0.0', () => {
logger.info(`Web server is now listening on port ${port}`);
});
module.exports = { app, server };