forked from dashroshan/Personal-Finance-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (44 loc) · 1.41 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
// Import required modules
const cors = require('cors');
const express = require('express');
const mongoose = require('mongoose');
const compression = require('compression');
const dotenv = require('dotenv');
const passport = require('passport');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
// Initialize express app
var app = express();
// Load env and set PORT
dotenv.config({ path: './secrets.env' });
const PORT = process.env.PORT;
// MongoDB connection
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
// Passport config
require('./config/passport')(passport);
// Middleware
app.use(cors({ credentials: true, origin: process.env.FRONTEND }));
app.use(express.json());
app.use(compression());
app.use(express.urlencoded({ extended: true }));
app.use(
session({
secret: process.env.PASSPORT_SECRET,
resave: true,
saveUninitialized: true,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
})
);
app.use(passport.initialize());
app.use(passport.session());
// Routes
app.use('/api/auth', require('./routes/auth'));
// Frontend site
const rootPath = __dirname;
app.use(express.static(rootPath + '/frontend'));
app.get('*', (req, res) => res.sendFile(rootPath + '/frontend/index.html'));
// Start server
app.listen(PORT, console.log(`Server started on port ${PORT}`));