forked from Tab-nabbers/Tab-Nabbers2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
82 lines (51 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express'),
session = require('express-session'),
bodyParser = require('body-parser'),
env = require('dotenv').load(),
secret = require("./back/config/secrets"),
path = require("path"),
webpack = require("webpack"),
open = require("open"),
passport = require("passport"),
mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/sequelize_passport');
const db = mongoose.connection;
db.on("error", function (err) {
console.log("Mongoose Error: ", err);
});
db.once("open", function () {
console.log("Mongoose connection successful!!!");
});
const config = require("./webpack.config");
require('./back/passport')(passport);
const app = express(),
PORT = process.env.PORT || 8080;
const router = express.Router();
const compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo:true,
publicPath:config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
// // Static directory
app.use(express.static(path.join(__dirname + "/app/public")));
//For BodyParser
app.use(bodyParser({ defer: true }));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
require("./back/passport")(passport);
app.use(session({
secret: 'ilovescotchscotchyscotchscotch', // session secret
resave: true,
saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());
require("./back/routes/authenticate")(app, passport);
require("./back/routes/html")(app, path);
//Sync Database
app.listen(PORT, function(err) {
if (!err)
console.log("Site is live");
else console.log("Database started fine!!!");
});