Skip to content

Commit 9769e52

Browse files
Bug Fixes on file responses and authorisation handlers
1 parent 340fed9 commit 9769e52

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

index.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,9 @@ Aeolus.prototype.www = function(path) {
4545

4646
Aeolus.prototype.load = function () {
4747
var SmartResource = require('./util/smartResource.js');
48-
var unauth = this.unauthorisedHandler;
4948
var getMethods = require('./util/getMethods.js');
5049
var methods = getMethods(this.methodPath);
5150

52-
var unauthorised = function(req,res) {
53-
if (unauth !== null) {
54-
unauth(req,res);
55-
} else {
56-
res.promptPassword("Please enter a Password");
57-
}
58-
};
59-
6051
for (var i = 0; i < methods.length; i++) {
6152
var name = methods[i].name;
6253
var resources = methods[i].resources;
@@ -74,6 +65,7 @@ Aeolus.prototype.load = function () {
7465

7566
var smartMethods = this.smartMethods;
7667
var error = this.errorHandler;
68+
var aeolus = this;
7769

7870
dispatcher.onError(function(req,res) {
7971
var Response = require('./util/response.js');
@@ -84,7 +76,7 @@ Aeolus.prototype.load = function () {
8476
return m.works(urlString,action);
8577
});
8678
if (methodsThatWork.length > 0) {
87-
var f = creator(methodsThatWork[0]);
79+
var f = aeolus.functionForResource(methodsThatWork[0]);
8880
f(req,res);
8981
} else {
9082
error(new Request(req),new Response(res));
@@ -97,6 +89,14 @@ Aeolus.prototype.functionForResource = function (resource) {
9789
var Response = require('./util/response.js');
9890
var Request = require('./util/request.js');
9991
var auther = this.authHandler;
92+
var unauth = this.unauthorisedHandler;
93+
var unauthorised = function(req,res) {
94+
if (unauth !== null) {
95+
unauth(req,res);
96+
} else {
97+
res.promptPassword("Please enter a Password");
98+
}
99+
};
100100
return function(re,r) {
101101
var res = new Response(r);
102102
var req = new Request(re,this);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aeolus",
3-
"version": "1.1.22",
3+
"version": "1.1.25",
44
"description": "AtomicLlama's fast and problem free framework for fast NodeJS Servers.",
55
"main": "index.js",
66
"scripts": {

util/response.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
14
var Response = function(res) {
25
this.res = res;
36
};
@@ -10,14 +13,15 @@ Response.prototype.respondJSON = function(object, status, headers) {
1013
};
1114

1215
Response.prototype.respondFile = function (filename, status) {
16+
filename = path.join(process.cwd(), filename);
17+
var res = this.res;
1318
fs.readFile(filename, "binary", function(err, file) {
14-
var h = headers || {};
1519
if(err) {
1620
throw err;
1721
} else {
18-
response.writeHead(status);
19-
response.write(file, "binary");
20-
response.end();
22+
res.writeHead(status || 200);
23+
res.write(file, "binary");
24+
res.end();
2125
}
2226
});
2327
};

0 commit comments

Comments
 (0)