-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
39 lines (30 loc) · 808 Bytes
/
Copy pathserver.js
File metadata and controls
39 lines (30 loc) · 808 Bytes
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
const express = require('express');
const session = require('express-session');
const cors = require('cors');
const SECRET = process.env.SECRET;
const routes = require('./api/routes/routes');
const server = express();
const corsOptions = {
origin: 'https://awesome-volhard-b3adaf.netlify.com',
// origin: 'http://localhost:3000',
credentials: true,
};
server.use(express.json());
server.use(cors(corsOptions));
// server.options('*', cors());
server.use(
session({
secret: SECRET,
resave: true,
saveUninitialized: false,
})
);
const restrictAccess = (req, res, next) => {
if (req.session.username) next();
else res.status(404).send({ msg: 'You must log in to view this page.' });
};
server.use('/api/notes', restrictAccess);
routes(server);
module.exports = {
server,
};