-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (40 loc) · 1.33 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
const express = require('express');
const app = express();
const session = require('express-session');
const cors = require('cors');
const ejs = require('ejs');
const path = require('path');
const methodOverride = require('method-override');
const connectDB = require('./db/connect');
require('dotenv').config();
app.use(cors());
app.options('*', cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.use(session({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true
}));
app.use(methodOverride('_method'));
app.get('/', (req, res) => { res.render('index'); });
app.get('/yurts', (req, res) => { res.render('yurts'); });
app.get('/reservations', (req, res) => { res.render('reservations'); });
app.get('/activities', (req, res) => { res.render('activities'); });
app.use('/reservations', require('./controllers/contact.js'));
const PORT = process.env.PORT || 3000;
const start = async () => {
try {
// Connect the DB first before starting the server
await connectDB();
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}...`);
});
} catch (err) {
console.log(err);
console.log('Error connecting to the MongoDB database');
}
};
start();