-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
54 lines (39 loc) · 1.48 KB
/
app.ts
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
'use strict';
require('dotenv').config();
const SwaggerExpress = require('swagger-express-mw');
const app = require('express')();
const SwaggerUi = require('swagger-tools/middleware/swagger-ui');
const helmet = require('helmet');
const config = require('./config/config');
const logger = require('./helpers/logger');
const morgan = require('morgan');
const geolib = require('geolib');
// Print HTTP VERB logs
if (config.MORGAN_LOG) { app.use(morgan('dev')); }
app.use(helmet());
module.exports = app; // for testing
const swaggerConfig = {
appRoot: __dirname // required config
};
SwaggerExpress.create(swaggerConfig, function (err, swaggerExpress) {
if (err) { throw err; }
if (config.PRODUCTION === 'true' || config.PRODUCTION === true) {
logger.info('Running in Production');
swaggerExpress.runner.swagger.host = config.PROD_HOST;
}
// Double equal signs to check for empty strings as well
if (config.API_KEY == false) {
logger.warn('Missing Google API Key');
}
// Use Swagger-UI, at /docs path
app.use(SwaggerUi(swaggerExpress.runner.swagger));
// install middleware
swaggerExpress.register(app);
logger.info(`Running on host: ${swaggerExpress.runner.swagger.host}`);
const port = process.env.PORT || 10010;
app.listen(port);
console.log(`Swagger docs are avialable at: ${swaggerExpress.runner.swagger.host}/docs`);
if (swaggerExpress.runner.swagger.paths['/hello']) {
console.log(`try this:\ncurl http://127.0.0.1:${port}/hello?name=Scott`);
}
});