-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
53 lines (42 loc) · 1.14 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
42
43
44
45
46
47
48
49
50
51
52
53
require('dotenv').config();
const cookieParser = require('cookie-parser');
const cors = require('cors');
const express = require('express');
const passport = require('passport');
const session = require('express-session');
const ensureAuth = require('./config/auth');
const app = express();
// Passport config
require('./config/passport')(passport);
// CORS and Bodyparser
app.use(
cors({
origin: 'https://opentimes.netlify.app',
credentials: true,
})
);
app.use(cookieParser());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Express session
app.use(
session({
secret: process.env.SECRET_KEY,
resave: true,
saveUninitialized: true,
})
);
//Passport middleware
app.use(passport.initialize());
app.use(passport.session());
// Routes
app.use('/api/users', require('./routes/users.js'));
app.use('/api/groups', require('./routes/groups.js'));
// Ensure authentication route
app.get('/api/checkAuth', ensureAuth, (req, res) => {
res.status(200).json('User is authenticated.');
});
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log('Login/Registration API running...');
});