-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
64 lines (53 loc) · 1.69 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
62
63
64
const path = require("path");
const User = require("./models/user");
const authConfig = require("./app/auth/passport");
const authentication = require("./app/auth/routes");
const bookApi = require("./app/api/books");
const settingsApi = require("./app/api/settings");
const tradeApi = require("./app/api/trade");
const routes = require("./app/routes");
const passport = require("passport");
const mongoose = require("mongoose");
const logger = require("connect-logger");
if(process.env.NODE_ENV !== "production") {
require("dotenv").config({
path: "config/.env"
});
}
mongoose.Promise = global.Promise;
mongoose.connect(process.env.DB_URI);
const session = require("express-session");
const bodyParser = require("body-parser");
const MongoStore = require("connect-mongo")(session);
const express = require("express");
const app = express();
if(process.env.NODE_ENV !== "production") {
app.use(logger());
}
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "client"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(session({
secret: process.env.SESSION_SECRET,
store: new MongoStore({
mongooseConnection: mongoose.connection
}),
cookie: {
maxAge: 12 * 24 * 60 * 60 * 1000 //2 weeks
},
resave: false,
saveUninitialized: false
}));
app.use(express.static(path.join(process.cwd(), "build", "client")));
authConfig(passport, User);
app.use(passport.initialize());
app.use(passport.session());
app.use(authentication({ social: ["github", "twitter"] }));
app.use(bookApi());
app.use(settingsApi());
app.use(tradeApi());
app.use(routes());
app.listen(process.env.PORT, () => {
console.log("listening on port: " + process.env.PORT);
});