-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (37 loc) · 1.34 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
const express = require('express');
require('express-async-errors');
const mongoose = require('mongoose');
const cors = require('cors');
const path = require('path');
const config = require('./utils/config');
const logger = require('./utils/logger');
const RestaurantRouter = require('./controller/restaurantRouter');
const userRouter = require('./controller/userRouter');
const loginRouter = require('./controller/login');
const reviewRouter = require('./controller/reviewRouter');
const middleware = require('./utils/middleware');
const app = express();
mongoose.connect(config.MONGODB_URI)
.then(() => {
logger.info('conntected to MongoDB');
})
.catch((err) => logger.error(err));
app.use(express.static('build'));
app.use(cors());
app.use(express.json());
app.use(middleware.requestLogger);
app.use(middleware.tokenExtractor);
app.use(middleware.userExtractor);
app.use('/api/food', RestaurantRouter);
app.use('/api/user', userRouter);
app.use('/api/login', loginRouter);
app.use('/api/review', reviewRouter);
app.get(['/login', '/food/*', '/new-restaurant', '/signup', '/profile', '/search'], (request, response) => {
response.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.get('/health', (request, response) => {
response.send('ok');
});
app.use(middleware.unknownEndpoint);
app.use(middleware.errorHandler);
module.exports = app;