-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (35 loc) · 1.34 KB
/
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
39
40
41
const express = require('express');
const app = express();
const path = require('path');
const cookieParser = require('cookie-parser');
const cors = require('cors');
const verifyJWT = require('./middleware/verifyJWT');
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.use(cookieParser());
app.use(cors({ origin: "*" , credentials: true }));
app.use('/', express.static(path.join(__dirname, '/public')));
// routes
// app.use('/', require('./routes/root'));
app.use('/register', require('./routes/api/register'));
app.use('/auth', require('./routes/api/auth'));
app.use('/refresh', require('./routes/api/refresh'));
app.use('/logout', require('./routes/api/logout'));
//everything after this line will require verifyJWT middleware!!!
app.use(verifyJWT);
app.use('/username', require('./routes/api/username'));
app.get('/protected', (req, res) => {
res.sendFile(path.join(__dirname, 'views', 'protectedpage.html'));
})
app.use('/friends', require('./routes/api/friends'))
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 running on port ${PORT}`));