-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
78 lines (63 loc) · 2.22 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
// Include Server Dependencies
const express = require("express");
const bodyParser = require("body-parser");
const methodOverride = require('method-override');
var cookieParser = require('cookie-parser');
const logger = require("morgan");
// Create Instance of Express
const app = express();
// Sets an initial port. We'll use this later in our listener
const PORT = process.env.PORT || 3000;
// Authentication Packages
var session = require('express-session');
var passport = require('passport');
// var MySQLStore = require('express-mysql-session')(session);
// initalize sequelize with session store
var SequelizeStore = require('connect-session-sequelize')(session.Store);
// -------------------------------------------------
// Initialize Sequelize
const db = require('./models');
// const Sequelize = require('sequelize');
// Static directory
app.use(express.static("public"));
// Run Morgan for Logging
app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
// var sequelize = new db.Sequelize(
// "Mambos",
// "root",
// "", {
// "dialect": "mysql",
// "storage": "./session.mysql"
// });
// var myStore = new SequelizeStore({
// db: sequelize
// });
// myStore.sync();
app.use(cookieParser()); // Possibly not needed for session
app.use(session({
// key: 'session_cookie_name',
secret: 'uefewehfybjboi', // could use random string generator
// store: myStore,
resave: false,
saveUninitialized: false, // Only creates cookie for logged in user
// cookie: { secure: true} // Only use if using HTTPS
}));
app.use(passport.initialize());
app.use(passport.session());
// // Override with POST having ?_method=DELETE
// app.use(methodOverride("_method"));
// -----------------------------------------------
// require routes
require('./routes/routes.js')(app);
require('./routes/login-routes.js')(app);
// Syncing our sequelize models and then starting our Express app
// =============================================================
db.sequelize.sync({ /*force: true*/ }).then(function() {
app.listen(PORT, function() {
console.log("App listening on PORT " + PORT);
})
});