-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
57 lines (44 loc) · 1.36 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
'use strict';
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const SwaggerExpress = require('swagger-express-mw');
const express = require('express');
const app = express();
app.disable('x-powered-by');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser')
const morgan = require('morgan');
const ev = require('express-validation');
const cors = require('cors');
const auth = require('./api/helpers/auth');
const path = require('path');
app.use(express.static(path.join('public')));
app.use(cors());
switch (app.get('env')) {
case 'development':
app.use(morgan('dev'));
break;
case 'production':
app.use(morgan('short'));
break;
default:
}
module.exports = app; // for testing
const config = {
appRoot: __dirname // required config
};
app.use('/api/v1/clients', auth.verifyLoggedIn);
app.use('/api/v1/search', auth.verifyLoggedIn);
app.use('/api/v1/ingredients', auth.verifyLoggedIn);
app.use('/api/v1/recipes', auth.verifyLoggedIn);
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
// install middleware
swaggerExpress.register(app);
const port = process.env.PORT || 10010;
app.listen(port);
if (swaggerExpress.runner.swagger.paths['/hello']) {
console.log('try this:\ncurl http://127.0.0.1:' + port + '/hello?name=Scott');
}
});