-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
68 lines (56 loc) · 1.76 KB
/
main.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
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const passport = require('passport');
const session = require('express-session');
const cookieParser = require('cookie-parser');
const log = require('./log');
const router = express.Router();
require('dotenv').config();
const app = express();
var fileupload = require("express-fileupload");
app.use(fileupload());
// Mongoose
mongoose.connect(process.env.MONGO_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
});
const db = mongoose.connection;
db.on('error', (error) => console.log(error));
db.once('open', () => log.log('MongoDB', 'Connected'));
// Middlewares
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// CORS
const whitelist = ['http://localhost:3000'];
const corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== 1) {
callback(null, true);
} else callback(new Error('Not allowed by CORS'));
},
credentials: true,
};
app.use(cors(corsOptions));
// Session Management
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
})
);
app.use(cookieParser(process.env.SESSION_SECRET));
app.use(passport.initialize());
app.use(passport.session());
require('./config/passport')(passport);
// Routes
app.use('/user', require('./routes/userRoute'));
app.use('/hospital', require('./routes/hospitalRoute'));
app.use('/bed', require('./routes/bedRoute'));
app.use('/booking', require('./routes/bookingRoute'));
app.use('/', require('./routes/firebaseRoute'));
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => log.log('Server', `Running on port ${PORT}`));