Skip to content

Commit 3f0a6e2

Browse files
committed
Load and show previous revisions.
1 parent 7b45952 commit 3f0a6e2

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

coder-apps/common/coderlib/app/app.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var fs = require('fs');
22
var util = require('util');
33
var async = require('async');
4+
var pathutil = require('path');
5+
var ncp = require('ncp');
46

57
var getDateString = function( d ) {
68
var now = new Date();
@@ -52,13 +54,6 @@ App.prototype.exec = function (req, res, path) {
5254
res.locals["coder_color"] = coderlib.device.color;
5355

5456

55-
//Redirect to sign-in for unauthenticated users
56-
var user = coderlib.auth.isAuthenticated(req, res);
57-
if ( !user && !this.metadata.public) {
58-
util.log( "redirect: " + '/app/auth' );
59-
res.redirect('/app/auth');
60-
return;
61-
}
6257

6358
this.require(function(err, userapp) {
6459
if (err) {
@@ -73,8 +68,8 @@ App.prototype.exec = function (req, res, path) {
7368
routes = userapp.post_routes;
7469
}
7570

71+
var found = false;
7672
if ( routes ) {
77-
var found = false;
7873
for ( var i in routes ) {
7974
route = routes[i];
8075
if ( route['path'] instanceof RegExp ) {
@@ -91,10 +86,10 @@ App.prototype.exec = function (req, res, path) {
9186
break;
9287
}
9388
}
89+
}
9490

95-
if ( !found ) {
96-
res.send(404);
97-
}
91+
if ( !found ) {
92+
res.send(404);
9893
}
9994
});
10095
}
@@ -136,8 +131,7 @@ LocalApp.prototype.require = function(callback) {
136131
};
137132

138133
LocalApp.prototype.view = function(name) {
139-
if (!name)
140-
name = "index";
134+
name = name || "index";
141135
return this.viewpath + name;
142136
};
143137

@@ -243,7 +237,7 @@ var createLinks = function(name, cb) {
243237

244238
LocalApp.create = function(template, name, callback) {
245239
var appPath = process.cwd() + "/apps/" + name;
246-
var templatePath = path.resolve("apps/", template);
240+
var templatePath = pathutil.resolve("apps/", template);
247241

248242
ncp(templatePath, appPath, function(err) {
249243
if (err) {

coder-apps/common/vcs/app/gitapp.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use strict";
22
var async = require("async");
33
var util = require("util");
4+
var pathutil = require("path");
45
var Git = require("./git");
6+
57
var App = coderlib.App;
68
var LocalApp = coderlib.LocalApp;
79

@@ -13,6 +15,9 @@ var GitApp = module.exports = function(name, rev) {
1315
this.repo = null;
1416
this.tree = null;
1517
this.module = null;
18+
19+
this.staticURL = pathutil.resolve('/app/vcs/static/', this.name, this.revision);
20+
this.appURL = pathutil.resolve('/app/vcs/app/', this.name, this.revision);
1621
};
1722

1823
util.inherits(GitApp, App);
@@ -57,13 +62,18 @@ GitApp.prototype.require = function(callback) {
5762
var m = new Module();
5863
m.paths = module.paths;
5964
m._compile(src, "/app/index.js");
60-
self.module = m;
65+
self.module = m.exports;
6166

62-
callback(null, m);
67+
callback(null, self.module);
6368
}
6469
], callback);
6570
};
6671

72+
GitApp.prototype.view = function(name) {
73+
name = name || "index";
74+
return "apps/" + this.name + "/" + name;
75+
}
76+
6777
GitApp.find = function(name, rev, callback) {
6878
callback = callback || function() {};
6979

coder-apps/common/vcs/app/index.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var isVersionned = function(app, callback) {
1212

1313
exports.get_routes = [
1414
{ path:'/', handler:'index_handler' },
15-
{ path:/^\/view\/(\w+)\/([0-9a-f]+)\/static\/(.+)$/, handler: 'static_handler' },
15+
{ path:/^\/app\/(\w+)\/([0-9a-f]+)(\/.*)?$/, handler: 'app_handler' },
16+
{ path:/^\/static\/(\w+)\/([0-9a-f]+)\/(.+)$/, handler: 'static_handler' },
1617
{ path:/^\/log\/(\w+)\/?$/, handler:'log_handler' }
1718
];
1819

@@ -45,7 +46,6 @@ exports.static_handler = function( app, req, res, match ) {
4546
], function(err, data) {
4647
if (err)
4748
{
48-
console.log(err);
4949
res.send(404);
5050
}
5151
else
@@ -56,12 +56,28 @@ exports.static_handler = function( app, req, res, match ) {
5656
});
5757
};
5858

59+
exports.app_handler = function( app, req, res, match ) {
60+
var appname = match[1];
61+
var rev = match[2];
62+
var path = match[3] || "/";
63+
64+
var repo;
65+
66+
GitApp.find(appname, rev, function(err, app) {
67+
if (err) {
68+
res.send(404);
69+
return;
70+
}
71+
72+
app.exec(req, res, path);
73+
});
74+
}
75+
5976
exports.log_handler = function( app, req, res, match ) {
6077
var appname = match[1];
6178

6279
GitApp.history(appname, function(err, results) {
63-
console.log(err);
64-
res.render( app.view("log"), {commits: results} );
80+
res.render( app.view("log"), {name: appname, commits: results} );
6581
});
6682
};
6783

coder-apps/common/vcs/views/log.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<h1>Log</h1>
2626
<ul>
2727
{{#commits}}
28-
<li>{{message}} - {{short}}</li>
28+
<li><a href="/app/vcs/app/{{name}}/{{short}}">{{message}} - {{short}}</a></li>
2929
{{/commits}}
3030
</ul>
3131
</div>

coder-base/server.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ var apphandler = function( req, res, appdir ) {
6060
return;
6161
}
6262

63+
//Redirect to sign-in for unauthenticated users
64+
var user = auth.isAuthenticated(req, res);
65+
if ( !user && !app.metadata.public) {
66+
util.log( "redirect: " + '/app/auth' );
67+
res.redirect('/app/auth');
68+
return;
69+
}
70+
6371
app.exec(req, res, apppath);
6472
});
6573
};

0 commit comments

Comments
 (0)