-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (38 loc) · 1.18 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
const express = require('express');
require('express-async-errors');
const cors = require('cors');
const morgan = require('morgan');
const path = require('path');
const compression = require('compression');
const app = express();
const placesRouter = require('./routes/places');
const checkinsRouter = require('./routes/checkins');
const personsRouter = require('./routes/persons');
const {
unknownEndpoint,
errorHandler,
authToken,
} = require('./utils/middleware');
const authRouter = require('./routes/auth');
if (process.env.NODE_ENV === 'development') {
app.use(morgan('tiny'));
}
app.use(cors());
app.use(express.json());
app.use(compression());
app.use('/api/auth', authRouter);
app.use('/api/places', placesRouter);
app.use('/api/checkins', authToken, checkinsRouter);
app.use('/api/persons', authToken, personsRouter);
app.get('/health', (req, res) => {
res.json({ ping: 'pong' });
});
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
}
app.use(unknownEndpoint);
app.use(errorHandler);
module.exports = app;