-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
96 lines (79 loc) · 3.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* //------------------------------------------------------------
SERVER.JS kk 553p
*/ //-------------------------------------------------------------
// Require ======================================================
require("dotenv").config();
const express = require("express");
const bodyParser = require("body-parser");
const exphbs = require("express-handlebars");
const session = require('express-session');
const cookieParser = require('cookie-parser');
const flash = require('connect-flash');
const path = require('path');
const passport = require('passport');
const static = require('express-static')
// Port and Models
var models = require("./models");
var PORT = process.env.PORT || 3000;
// Express --------------------------
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Passport --------------------------
app.use(session({ secret: 'keyboard cat', resave: true, saveUninitialized: true })); // session secret
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
// ------------------------------------------------------------
// Routes ======================================================
// ------------------------------------------------------------
// USER page ========================================================
app.get('/user', checkAuthentication, function (req, res) {
res.sendFile(path.join(__dirname + '/public/user.html'));
});
function checkAuthentication(req, res, next) {
if (req.isAuthenticated()) {
//req.isAuthenticated() will return true if user is logged in
next();
} else {
res.redirect("/");
}
}
//app.get('/user', function (req, res) {
// res.sendFile(path.join(__dirname + '/public/user.html'));
//});
// // LOGIN Dashboard ========================================================
app.get('/login', function (req, res) {
res.sendFile(path.join(__dirname + '/public/login.html'));
console.log('works');
});
// Stories page ========================================================
app.get('/stories', function (req, res) {
res.sendFile(path.join(__dirname + '/public/stories.html'));
});
// Blog Post page ========================================================
app.get('/blog-post', function (req, res) {
res.sendFile(path.join(__dirname + '/public/blog-post.html'));
});
// Friends & Followers page ========================================================
app.get('/friends', function (req, res) {
res.sendFile(path.join(__dirname + '/public/friends.html'));
});
require("./routes/apiRoutes")(app, passport);
require("./routes/auth.js")(app, passport);
require("./routes/htmlRoutes.js")(app, passport);
//load passport strategies
require('./config/passport/passport.js')(passport, models.user);
var syncOptions = { force: false };
// If running a test, set syncOptions.force to true
// clearing the `testdb`
if (process.env.NODE_ENV === "test") {
syncOptions.force = true;
}
// Starting the server, syncing our models ==========================================
models.sequelize.sync(syncOptions).then(function () {
console.log(process.env.NODE_ENV)
app.listen(PORT, function () {
console.log(
"Some badass people starting baddass servers on: http://localhost:" + PORT);
});
});