This repository has been archived by the owner on Apr 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
58 lines (48 loc) · 1.47 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
// Imports
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const cookie = require("cookie-parser");
const session = require("express-session");
const passport = require("./config/passport");
var path = require("path");
const dotenv = require("dotenv");
dotenv.config();
const PORT = process.env.PORT || 3000;
// Setting up express
var app = express();
//Routes
var routes = require("./routes/route");
// Database Connection
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://" + process.env.DB_USER + ":" + process.env.DB_PASS + "@" + process.env.DB_HOST, { useNewUrlParser: true });
// Middlewares for Static files
app.use("/assets", express.static("assets"));
// app.use('/images', express.static('images'));
//app.use(express.static(path.join(__dirname, 'assets')));
//app.use(express.static(path.join(__dirname, 'images')));
//console.log(path.join(__dirname, 'images'));
// Template Engine
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
//Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
//Cookie
app.use(cookie());
//Session
app.use(
session({
secret: "Site visit",
resave: true,
saveUninitialized: true,
cookie: { secure: false, maxAge: 900000 }
})
);
passport(app);
// call the routes
app.use(routes);
// Port deploy & debug
app.listen(PORT, function() {
console.log("Server listening on port " + PORT);
});