-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
38 lines (31 loc) · 873 Bytes
/
server.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
const path = require('path');
const express = require('express');
const app = express();
// json log middleware
app.use(function (req, res, next) {
console.log(`request url: ${req.url}`);
next()
});
// json parser middleware
app.use(express.json());
// static files middleware
app.use(express.static(path.join(__dirname, 'public')));
const clubsRouter = require('./api/clubs/clubs.route');
const roundsRouter = require('./api/rounds/rounds.route');
app.use('/api', clubsRouter);
app.use('/api', roundsRouter);
// index file
app.get('/', (req, res, next) => {
res.sendFile(path.join(__dirname, 'public/index.html'));
next();
});
// error handling
app.use((err, req, res, next) => {
if(err) {
res.sendFile(path.join(__dirname, 'public/error.html'));
}
next();
});
app.listen(3000,
() => console.log('football data server listening on port 3000')
);