-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (26 loc) · 884 Bytes
/
server.js
File metadata and controls
35 lines (26 loc) · 884 Bytes
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
const express = require('express');
const cors = require('cors');
const path = require('path');
const ip = require('ip');
require('dotenv').config();
const app = express();
app.use(cors());
// Init Middleware
app.use(express.json({ limit: '500mb' }));
app.use(express.urlencoded({ extended: true }));
app.use('/api', require('./routes/api/index.js'));
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/dist'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'dist', 'index.html'));
});
app.post('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'dist', 'index.html'));
});
}
const PORT = process.env.PORT || 443;
const server = app.listen(PORT, async () => {
console.log(`Server started on ${ip.address()}: ${PORT}`);
});