-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (37 loc) · 1.13 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
require('dotenv').config();
const express = require('express');
const cookieParser = require('cookie-parser');
const cron = require('node-cron');
const app = express();
const port = process.env.PORT;
// dbConnection
require('./dbConnection/mongo');
// Body Parser
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Cookie Parser
app.use(cookieParser());
// Disables CORS
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", process.env.CROSS_ORIGIN);
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Import the routes
const index = require('./routes/index');
const authorize = require('./routes/authorize');
const calendar = require('./routes/calendar');
// Tell app to use the routes
app.use(index);
app.use(authorize);
app.use(calendar);
// Run cron jobs
const { refreshTokens } = require('./helpers/auth');
cron.schedule('0 * * * *', () => {
// Refreshes tokens every hour
refreshTokens()
});
app.listen(port, () => {
console.log(`Listening on server port: ${port}`);
});