diff options
Diffstat (limited to 'backend/src/index.js')
| -rw-r--r-- | backend/src/index.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/backend/src/index.js b/backend/src/index.js index 04d13cc..6978225 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -3,14 +3,16 @@ require('dotenv').config({ path: 'variables.env' }); /* eslint-enable */ const jwt = require('jsonwebtoken'); const createServer = require('./createServer'); +const cookieParser = require('cookie-parser'); const server = createServer(); +server.express.use(cookieParser()); + // 1. Check JWT server.express.use((req, res, next) => { - const Authorization = req.get('Authorization'); - if (Authorization) { - const token = Authorization.replace('Bearer ', ''); + const { token } = req.cookies; + if (token) { const { userId } = jwt.verify(token, process.env.APP_SECRET); req.userId = userId; } @@ -30,6 +32,15 @@ server.express.use(async (req, res, next) => { next(); }); -server.start({ port: 4444 }, deets => { - console.log(`Server is running on http://localhost:${deets.port}`); -}); +server.start( + { + cors: { + credentials: true, + origin: process.env.FRONTEND_URL, + }, + port: 4444, + }, + deets => { + console.log(`Server is running on http://localhost:${deets.port}`); + } +); |
