This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
73 lines (64 loc) · 2.25 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
const model = require('./model');
exports.index = function(req, res){
model.App.all(req.getAuthDetails().user.user_id,
function(xs){
res.render('app/index',
{ title : 'Dashboard',
apps : xs });
});
};
exports.new = function(req, res){
res.render('app/new',{title: 'Create new application'});
};
exports.create = function(req, res){
model.App.create(req.body.title,
req.getAuthDetails().user.user_id,
function(error){
if(error){
res.send('app create error:' + error);
}else{
res.redirect('/app/');
}
});
};
exports.show = function(req, res){
model.App.get(req.params.app,
function(app) {
res.render("app/show",
{ title : app.title,
app : app })
});
};
exports.edit = function(req, res){
model.App.get(req.params.app,
function(app) {
res.render("app/edit",
{ title : 'Edit: ' + app.title,
app : app })
});
};
exports.update = function(req, res){
model.App.update(req.params.app,
{ title : req.body.title },
function(){
res.redirect("/app/" + req.params.app)
});
};
exports.destroy = function(req, res){
model.App.remove(req.params.app,
function() {
res.redirect("/app/")
});
};
exports.extras = function(server,listen,name) {
server.get('/' + name + '/:app/getting_start',function(req, res) {
const protocol = req.headers['x-forwarded-proto'] || req.protocol;
const hostname = req.headers.host;
model.App.get(req.params.app, function(app) {
res.render("app/getting_start",
{ title : "Getting start",
address : protocol + "://" + hostname,
app : app })
});
})
}