-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
63 lines (55 loc) · 2.04 KB
/
app.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
var express = require("express");
var path = require("path");
var logger = require("morgan");
var cookieParser = require("cookie-parser");
var bodyParser = require("body-parser");
var exphbs = require("express-handlebars");
var mongoose = require("mongoose");
var session = require('express-session');
var favicon = require('serve-favicon');
var argv = require('minimist')(process.argv.slice(2));
var olinAuth = require('./routes/olinAuth');
var project = require("./routes/project");
var user = require("./routes/user");
var app = express();
var PORT = process.env.PORT || 3000;
var mongoURI = process.env.MONGOURI || "mongodb://localhost/slac";
var hbs = exphbs.create({
defaultLayout: "main",
// Specify helpers which are only registered on this instance.
helpers: {
json: function(context) { return JSON.stringify(context); },
debug: function(context) { console.log(context);}
}
});
app.engine("handlebars", hbs.engine);
app.set("view engine", "handlebars");
// Debug Logger
console.dlog = function(message) {
if (argv.debug) {
var args = Array.prototype.slice.call(arguments, 1)
console.log(">>", message, args.join(','));
}
};
app.use(logger(argv.debug ? "dev" : "tiny"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({
secret: 'secret',
resave: false,
saveUninitialized: true
}));
app.use(express.static(path.join(__dirname, "public")));
app.use(favicon(__dirname + '/public/images/favicon.ico'));
app.use("/olinAuth", olinAuth);
app.use("/build", project.buildRequest, olinAuth.isAuth, user.getPublicUser, project);
app.use("/portfolio", project.portfolioRequest, user.getPublicUser, project)
app.use("/ideate", project.ideateRequest, olinAuth.isAuth, user.getPublicUser, project)
app.use("/user", olinAuth.isAuth, user.getPublicUser, user)
app.use("/", project.portfolioRequest, user.getPublicUser, project);
mongoose.connect(mongoURI);
app.listen(PORT, function() {
console.log("Application running on port:", PORT);
console.log("MongoURI:", mongoURI);
});