-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (26 loc) · 825 Bytes
/
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
const { NODE_ENV = 'dev' } = process.env;
require('dotenv').config({ path: `./${NODE_ENV}.env` });
const cors = require('cors');
const path = require('path');
const express = require('express');
const app = express();
const apiRouter = require('./routes/api.js');
const {
handleCustomErrors,
handlePsqlErrors,
handleInternalErrors,
} = require('./controllers/errors');
app.use(cors());
app.use(express.json());
app.use(express.static(path.join(__dirname, 'public', 'build')));
app.get('/', (req, res, next) => {
res.sendFile(path.join(__dirname, 'build', 'public', 'index.html'));
});
app.use('/api', apiRouter);
app.all('/*', (req, res, next) => {
next({ status: 404, msg: 'Route not found' });
});
app.use(handleCustomErrors);
app.use(handlePsqlErrors);
app.use(handleInternalErrors);
module.exports = app;