forked from Hack-A-Duck/Hack-A-Duck-SUPMI6E
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (35 loc) · 917 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
const express = require('express');
const cors = require('cors');
const cookieParser = require('cookie-parser');
const morgan = require('morgan');
const blogRouter = require('./routes/blogRouter');
const userRouter = require('./routes/userRouter');
const app = express();
app.use(
cors({
origin: 'http://127.0.0.1:5500',
credentials: true,
})
);
app.use(express.json());
app.use(cookieParser());
app.use(morgan('dev'));
app.use(express.static(`${__dirname}/public`))
app.use((req, res, next) => {
//console.log(req.cookies.token);
next();
});
app.use('/api/blogs', blogRouter);
app.use('/api/users', userRouter);
app.all('*', (req, res, next) => {
console.log(req.originalUrl);
next(new Error('Not Found'));
});
app.use((err, req, res, next) => {
console.log('err detected', err.message);
res.status(500).json({
status: 'error',
message: err.message,
});
});
module.exports = app;