-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (51 loc) · 1.4 KB
/
app.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
const express = require("express");
const mongoose = require("mongoose");
const morgan = require("morgan"); //logs
const expressLayouts = require("express-ejs-layouts");
const path = require("path");
const passport = require("passport");
const session = require("express-session");
const MongoStore = require('connect-mongo');
//load config
require("dotenv").config();
//passport config
require("./passport")(passport);
const app = express();
const PORT = process.env.PORT || 3000;
//middlewares
// app.use(morgan('dev')) //logs middlewares
app.use(express.json());
app.use(express.urlencoded({ extented:false }));
app.use(expressLayouts);
app.set("view engine", "ejs");
app.use(express.static(path.join(__dirname, "public")));
app.use(session({
secret:'mimi',
resave: false,
saveUninitialized: false,
store: MongoStore.create({
mongoUrl:process.env.MONGO_URI
})
}
));
app.use(passport.initialize());
app.use(passport.session())
//connect db
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("db connected");
})
.catch((err) => console.log(err));
//routes
app.use("/", require("./routes/index"));
app.use("/auth", require("./routes/auth"))
app.use("/blog",require("./routes/blog"))
app.use("/user",require("./routes/user"))
//run server
app.listen(PORT, () => {
console.log(`server running on port ${PORT}`);
});