-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
55 lines (46 loc) · 1.37 KB
/
index.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
54
55
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const path = require('path');
const session = require('express-session');
const flash = require('connect-flash');
const passport = require('./config/passport'); // Import passport from the new file
const app = express();
// Middleware setup
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Set EJS as the view engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
// Session setup
app.use(
session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: true,
})
);
// Initialize Passport
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
// Flash messages middleware
app.use((req, res, next) => {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.warning_msg = req.flash('warning_msg');
res.locals.error = req.flash('error');
next();
});
// Import routes
const getRoutes = require('./routes/getRoutes');
const postRoutes = require('./routes/postRoutes');
// Use routes
app.use('/', getRoutes);
app.use('/', postRoutes);
// Start the server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});