-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
91 lines (73 loc) · 2.41 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const express = require("express");
const app = express();
const path = require('path')
const passport = require("passport");
const session = require("express-session");
const MongoStore = require("connect-mongo");
const methodOverride = require("method-override");
const flash = require("express-flash");
const logger = require("morgan");
const PORT = 8000
const cors = require("cors")
const connectDB = require("./config/database");
const indexRoutes = require('./routes/IndexRoutes')
const dashboardRoutes = require('./routes/dashboardRoutes')
const notesRoutes = require('./routes/notesRoutes')
const flashcardRoutes = require('./routes/flashcardRoutes')
const resourceRoutes = require('./routes/resourceRoutes')
const taskRoutes = require('./routes/taskRoutes.js')
//Use .env file in config folder
require("dotenv").config({ path: "./config/.env" })
// Passport config
require("./config/passport")(passport);
//Using EJS for views
// app.set("view engine", "ejs");
app.use(cors({
origin: (origin, callback) => callback(null, true),
credentials: true
}));
//Static Folder
app.use(express.static("client/build"));
//Body Parsing
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
//Logging
app.use(logger("dev"));
//Use forms for put / delete
app.use(methodOverride("_method"));
// Setup Sessions - stored in MongoDB
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: false,
store: MongoStore.create({mongoUrl: process.env.MONGO_URL})
}))
// Passport middleware
app.use(passport.initialize());
app.use(passport.session());
//Use flash messages for errors, info, ect...
app.use(flash());
//Connect To Database
connectDB()
app.use('/', indexRoutes)
app.use('/api/dashboard', dashboardRoutes)
app.use('/api/assignments', taskRoutes)
app.use('/api/notes', notesRoutes)
app.use('/api/flashcards', flashcardRoutes)
app.use('/api/resources', resourceRoutes)
app.use('*', (req, res) => {
res.sendFile(path.join(__dirname, '/client/build/index.html'));
});
app.listen(process.env.PORT||PORT, ()=>{
console.log(`running on port ${PORT}`)
})
const makeRequest = async () => {
try {
const url=process.env.NODE_ENV =="development" ? "http://localhost:8000/api/user" : "https://mindful-math.onrender.com/api/user"
const res = await fetch(url)
const data= await res.text()
} catch (error) {
console.log("ERROR: ",error)
}
}
setInterval(makeRequest, 10*60*1000);