-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
81 lines (60 loc) · 3.05 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
///////////////////////////////////////////////////
/////////////////////importing////////////////////
/////////////////////////////////////////////////
var express = require("express");
var mongoose = require("mongoose");
var passport = require("passport");
var handlebars = require("express-handlebars");
///////////////////////////////////////////////////
////////////////////configuring///////////////////
/////////////////////////////////////////////////
application = express();
application.use(require("cookie-parser")());
application.use(require("body-parser").json());
application.use(require("body-parser").urlencoded({extended: true}));
application.use(require("express-session")({secret: "exieeecs", saveUninitialized: true, resave: true}));
application.use(require("connect-flash")());
///////////////////////////////////////////////////
////////////////////databasing////////////////////
/////////////////////////////////////////////////
require("./database.js").initiate();
///////////////////////////////////////////////////
////////////////////templating////////////////////
/////////////////////////////////////////////////
var options = require("./configs/handlebars.options.js");
application.engine(".html", handlebars(options));
application.set("view engine", ".html");
application.set("views", "./content");
///////////////////////////////////////////////////
//////////////////authenticating//////////////////
/////////////////////////////////////////////////
passport.serializeUser(function(user, done) {done(null, user)});
passport.deserializeUser(function(user, done) {done(null, user)});
var LocalStrategy = require("passport-local").Strategy;
var configuration = require("./configs/passport.configuration.js");
var login_callback = require("./configs/passport.login.callback.js");
var signup_callback = require("./configs/passport.signup.callback.js");
passport.use("local-login", new LocalStrategy(configuration, login_callback));
passport.use("local-signup", new LocalStrategy(configuration, signup_callback));
application.use(passport.initialize());
application.use(passport.session());
///////////////////////////////////////////////////
/////////////////////routing//////////////////////
/////////////////////////////////////////////////
application.use(require("express").static("./resources"));
application.use(require("./middleware/get-flash-locals.js"));
application.use(require("./middleware/get-user-locals.js"));
application.use("/", require("./routes/home.route.js")());
application.use("/", require("./routes/auth.route.js")(passport));
application.use("/profile", require("./routes/profile.route.js")());
application.use("/tutoring", require("./routes/tutoring.route.js")());
application.use("*", require("./routes/error.route.js")());
///////////////////////////////////////////////////
////////////////////listening/////////////////////
/////////////////////////////////////////////////
var port = process.env.PORT || 80;
application.listen(port, function()
{
//console.log("Established the server.");
//console.log("Listening on port " + port + ".");
});