-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
61 lines (33 loc) · 1.19 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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const methodOverride = require("method-override");
const morgan = require("morgan");
const session = require('express-session');
const app = express();
mongoose.connect(process.env.MONGODB_URI);
mongoose.connection.on("connected", () => {
console.log(`Connected to MongoDB ${mongoose.connection.name}.`);
});
app.use(morgan('dev'));
app.use(express.static('public'));
app.use(express.urlencoded({ extended: false }));
app.use(methodOverride("_method"));
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: true
}));
app.use('/uploads', express.static('uploads'));
const addUserToReqAndLocals = require('./middleware/addUserToReqAndLocals');
app.use(addUserToReqAndLocals);
const ensureLoggedIn = require('./middleware/ensureLoggedIn');
app.use('/auth', require('./controllers/auth'));
app.use('/cars', require('./controllers/cars'));
app.get('/', async (req, res) => {
res.render('home.ejs');
});
const port = process.env.PORT ? process.env.PORT : "3000";
app.listen(port, () => {
console.log(`The express app is ready on port ${port}!`);
});