-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (47 loc) · 1.59 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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const config = require('./config').get();
const environment = require('./config').getEnv();
const swaggerUi = require('swagger-ui-express');
const swaggerSpec = require('./swagger-config');
// Express.js configuration.
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// app.use(compression());
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE');
if (req.method === 'OPTIONS') {
res.send(200);
}
else {
next();
}
});
// Root endpoint.
app.get('/', (req, res) => {
res.send('Environment' + process.env.NODE_ENV);
});
app.get('/health-check', (req, res) => res.sendStatus(200));
app.use('/api/pokemon', require('./routes/pokemon'));
// Error handling middleware.
// app.use(errorHandler);
// Public folder for public static assets.
app.use(express.static('public'));
// Swagger documentation specification
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
// Listen for requests on the specified port.
const port = process.env.PORT || config.port;
app.listen(port);
// Print handy environment info on the console after.
console.log(process.version);
console.log(environment);
console.log('Listening on port: ' + port);