-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (21 loc) · 762 Bytes
/
server.js
File metadata and controls
27 lines (21 loc) · 762 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
const path = require('path');
const express = require('express');
const app = express();
const PORT = process.env.PORT || 5050;
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use('/', express.static(path.join(__dirname, '/public')));
app.use('/', require('./routes/root'));
// Api Endpoints
app.use('/requests', require('./routes/api/userRequests'));
app.all('*', (req, res) => {
res.status(404);
if (req.accepts('html')) {
res.sendFile(path.join(__dirname, 'views', '404.html'));
} else if (req.accepts('json')) {
res.json({ error: '404 Not Found' });
} else {
res.type('txt').send('404 Not Found');
}
});
app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));