forked from AnimeAllstar/UBSee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (31 loc) · 1023 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
33
34
35
36
37
38
39
40
const express = require('express');
const compression = require('compression');
const helmet = require('helmet');
const path = require('path');
const apiRoutes = require('./api/routes/api');
const errorController = require('./api/controllers/error');
const mongoConnect = require('./api/utils/database').connect;
const app = express();
// Serve the static files from the React app
app.use(express.static(path.join(__dirname, 'client', 'build')));
// security
app.use(
helmet({
contentSecurityPolicy: false,
})
);
// Asset compression
app.use(compression());
// api routes
app.use('/api/', apiRoutes);
// api route not found
app.use('/api/*', errorController.notFound);
// hanldles client side requests statically
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});
mongoConnect(() => {
app.listen(process.env.PORT || 8080, () => {
console.log('listening on ' + (process.env.PORT ? `port ${process.env.PORT}` : 'http://localhost:8080/'));
});
});