-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
61 lines (43 loc) · 1.75 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
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
var exphbs = require("express-handlebars");
var iifym = require("iifym.js");
var env = require('dotenv').load();
var session = require('express-session');
var passport = require('passport');
app.use(session({ secret: 'keyboard cat',resave: true, saveUninitialized:true})); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
// Sets up the Express App
// =============================================================
var PORT = process.env.PORT || 8080;
app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");
// Requiring our models for syncing
var models = require("./models");
// Sets up the Express app to handle data parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
// Static directory
app.use(express.static("public"));
app.listen(PORT, function(err) {
if (!err)
console.log("Site is live");
else console.log(err);
});
// Routes
// =============================================================
require('./config/passport.js')(passport, models.user);
require("./routes/api-routes.js")(app);
require('./routes/auth.js')(app,passport);
require("./routes/html-routes.js")(app);
// Syncing our sequelize models and then starting our Express app
// =============================================================
models.sequelize.sync().then(function() {
console.log('Nice! Database looks great. Listening on PORT'+ PORT);
}).catch(function(err) {
console.log(err, "Something went wrong with the database update!");
});