-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (45 loc) · 1.57 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
const express = require("express");
const app = express();
const path = require("path");
const cors = require("cors");
const env = require("dotenv").config();
const passport = require("./passport");
const express_session = require("express-session");
const mongoose = require("mongoose");
const login = require("./router/login");
const signup = require("./router/signup");
const explore = require("./router/explore");
const profile = require("./router/profile");
const user = require("./router/user");
const post = require("./router/post");
const PORT = process.env.PORT || 3000;
const mongo_uri = process.env.mongo_uri;
mongoose.connect(mongo_uri,{ useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: false })
.then(()=>{
console.log("db connection successfull !");
app.listen(PORT, ()=>{
console.log("server started on port number: ",PORT);
})
})
.catch((err)=>{
console.log("error : ",err);
})
app.use(express.static(path.join(__dirname , 'public')));
app.engine('html', require('ejs').renderFile);
app.set('views', path.join(__dirname, '/public/html'));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(cors({ origin: true, credentials: true }));
app.use(express_session({
secret: process.env.express_session_secret,
resave: false,
saveUninitialized: true,
}));
app.use(passport.initialize());
app.use(passport.session());
app.use("/login",login);
app.use("/signup",signup);
app.use("/",explore);
app.use("/user",user);
app.use("/post",post);
app.use("/profile",profile);