-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
116 lines (89 loc) · 2.86 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var express = require("express");
var bodyParser = require("body-parser");
var session = require("express-session");
var cookieParser = require("cookie-parser");
var compression = require("compression");
var path = require("path");
var engine = require("ejs-locals"); //讓express支援layout
var helper = require("./helper");
var User = require("./model/User");
var logger = require("morgan");
var app = express();
app.engine("ejs", engine);
app.set("views",path.join(__dirname,"views")); //view的路徑位在資料夾views中
app.set("view engine","ejs");
app.use(logger("tiny"));
app.use(compression());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use("/assets",express.static("assets",{ maxAge: 24*60*60 }));
app.use("/uploads",express.static("uploads"));
//Handle sessions and cookie
app.use(cookieParser("secretString"));
app.use(session({
cookie: { maxAge: 1000 * 60 * 60 * 24 },
secret:"secret",
resave: true,
saveUninitialized: true,
}));
var userInfo = ["_id", "Email", "EmailConfirm", "Name","School", "RecoveryEmail", "Major", "Skill", "Introduction", "Location", "Role", "Link", "GroupID", "ProjectID", "ActivityID","portfolio","Avatar"];
app.use(function(req, res, next) {
helper.noinjection(req);
res.locals.query = req.query;
if(req.cookies.isLogin){
User.findById(req.cookies.id,userInfo).populate("GroupID","_id Name").populate("ProjectID","_id Name").populate("ActivityID","_id Name").exec(function(err,user){
req.user = user;
res.locals.me = user;
next();
});
}
else {
res.locals.me = false;
next();
}
});
//mobile
var mobile = require("./controller/mobile");
app.use("/m",mobile);
//users routes
var users = require("./controller/users");
app.use("/users",users);
//projects routes
var projects = require("./controller/projects");
app.use("/projects",projects);
//activities routes
var activities = require("./controller/activities");
app.use("/activities",activities);
//groups routes
var groups = require("./controller/groups");
app.use("/groups",groups);
//panel routes
var panel = require("./controller/panel");
app.use("/panel",helper.checkLogin(),panel);
//messages routes
var messages = require("./controller/messages");
app.use("/messages",messages);
//payment routes
var payment = require("./controller/payment");
app.use("/payment",payment);
//search routes
var search = require("./controller/search");
app.use("/search",search);
// app.get("/about",function(req,res){
// res.render("about");
// });
//home routes (what's on)
var whatOn = require("./controller/whatOn");
app.use("/",whatOn);
//insert
app.get("/space",function(req,res){
res.render("space");
});
app.get("/whaton",function(req,res){
res.render("what_on");
});
// app.get("/*",function(req,res){
// res.render("index");
// });
app.listen( process.env.PORT || 5000);
console.log("running on port 5000");