-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
41 lines (35 loc) · 1.15 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 cookieParser = require('cookie-parser');
const userRoutes = require('./routes/user.routes');
const postRoutes = require('./routes/post.routes')
require('dotenv').config({path: './config/.env'});
require('./config/db')
const {checkUser, requireAuth } = require('./middleware/auth.middleware');
const cors = require('cors');
const app = express();
app.use(cors());
// const corsOptions = {
// origin: process.env.CLIENT_URL,
// credentials: true,
// 'allowedHeaders': ['sessionId', 'Content-Type'],
// 'exposedHeaders': ['sessionId'],
// 'method': 'GET,HEAD,PUT,POST,DELETE',
// 'preflightContinue': false
// }
//app.use(cors(corsOptions))
//app.use(cors({origin: process.env.CLIENT_URL}))
app.use(express.json());
app.use(cookieParser());
app.use(express.static(__dirname + '/client/public'));
//jwt
app.get('*', checkUser);
app.get('/jwtid', requireAuth, (req, res) => {
res.status(200).send(res.locals.user._id)
});
// routes
app.use('/api/user', userRoutes);
app.use('/api/post', postRoutes);
// server
app.listen(process.env.PORT, ()=> {
console.log(`Listening on port ${process.env.PORT}`);
} )