-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
42 lines (34 loc) · 1.17 KB
/
server.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
import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import morgan from 'morgan';
import parsePage from './src/middleware/parse-page';
// initialize models
import './src/models';
import {routes as authRouter} from './src/controllers/auth';
import {routes as recipeRouter} from './src/controllers/recipe';
import {routes as userRecipesRouter} from './src/controllers/user-recipes';
import {routes as streamRouter} from './src/controllers/stream';
import {routes as ingredientsRouter} from './src/controllers/ingredients';
import {routes as pantryRouter} from './src/controllers/pantry';
const app = express();
// CORS is hard
app.use(cors());
app.options('*', cors());
// middleware
app.use(morgan(process.env.NODE_ENV === 'production' ? 'short' : 'dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(parsePage());
// controllers
app.use(authRouter());
app.use(recipeRouter());
app.use(userRecipesRouter());
app.use(streamRouter());
app.use(ingredientsRouter());
app.use(pantryRouter());
app.use((err, req, res, next) => {
console.error(`ERROR: ${err.message}`);
next();
});
export default app;