-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (68 loc) · 2.23 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config();
}
const express = require('express');
const mongoose = require('mongoose');
const passport = require('passport');
const session = require('express-session');
const MongoStore = require('connect-mongo');
const path = require('path');
require('./config/passport')(passport)
mongoose.connect(process.env.DB_URL || 'mongodb://localhost:27017/acadapp');
const db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", ()=>{
console.log("Database connected");
});
const app = express();
if (process.env.NODE_ENV !== 'production') {
app.use(require('cors')())
}
app.use(express.urlencoded({extended:true}));
app.use(express.json())
app.use(express.static(path.resolve(__dirname, './frontend/dist')));
// Sessions
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
expires: 30*24*60*60*1000
},
store: MongoStore.create({mongoUrl: process.env.DB_URL||'mongodb://localhost:27017/acadapp'}),
})
);
// Passport middleware
app.use(passport.session());
app.use('/add', require('./routes/add'));
app.use('/auth', require('./routes/auth'));
app.use('/posts', require('./routes/post'));
app.use('/subject', require('./routes/subject'));
app.use('/settings', require('./routes/settings'));
app.use('/notification', require('./routes/notification'));
// app.get('/', (req,res)=>{
// // console.log(req.headers);
// res.send("Hello, world!");
// });
const Subject = require('./models/Subject');
const Dept = require('./models/Dept');
const { isLoggedIn } = require('./middleware');
// app.get('/subjects', async(req,res)=>{
// let subjects = await Subject.find({});
// res.status(200).send(subjects);
// })
// app.get('/dept', async(req,res)=>{
// let depts = await Dept.find({});
// res.status(200).send(depts);
// })
// app.post('/subjects', async(req,res)=>{
// let subjects = await Subject.find({});
// res.send(subjects);
// })
app.route('*').get((req, res) => {
res.sendFile(path.resolve(__dirname, './frontend/dist', 'index.html'));
});
app.listen(3000, ()=>{
console.log('server started on port 3000');
});