Comparing version 0.1.8 to 0.1.9
@@ -80,3 +80,3 @@ /* | ||
}, | ||
serve: function (req, res) { | ||
serve: function (req, res, config) { | ||
var self = this, | ||
@@ -87,7 +87,14 @@ base = this.validate(req), | ||
query, | ||
data; | ||
data, | ||
dirroot = __dirname; | ||
config = config || {}; | ||
if (config.dirroot) { | ||
dirroot = config.dirroot; | ||
} | ||
if (base && base !== true) { | ||
if (this.scheme[base]) { | ||
query = parse(req.url).query, | ||
query = parse(req.url).query; | ||
parsed = qs.parse(query); | ||
@@ -98,4 +105,5 @@ | ||
} else if (parsed.file) { | ||
filepath = path.join(__dirname, parsed.file); | ||
filepath = path.join(dirroot, parsed.file); | ||
fs.readFile(filepath, function (err, data) { | ||
/*istanbul ignore next*/ | ||
if (err) { | ||
@@ -102,0 +110,0 @@ self.scheme.status(404, res); |
@@ -5,3 +5,3 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"devDependencies": { | ||
@@ -8,0 +8,0 @@ "vows": "*", |
@@ -14,12 +14,16 @@ var vows = require('vows'), | ||
var server = http.createServer(function(req, res) { | ||
var conf = { | ||
dirroot: __dirname | ||
}; | ||
if (req.url.indexOf('-express') > -1) { | ||
conf = null; | ||
var p = parse(req.url); | ||
req.url = req.url.replace('-express', ''); | ||
req.body = qs.parse(p.query); | ||
echoecho.serve(req, res); | ||
echoecho.serve(req, res, conf); | ||
} else if (echoecho.handle(req)) { | ||
echoecho.serve(req, res); | ||
echoecho.serve(req, res, conf); | ||
} else { | ||
if (req.url.indexOf('skipthisrequest') > -1) { | ||
echoecho.serve(req, res); | ||
echoecho.serve(req, res, conf); | ||
} else { | ||
@@ -838,3 +842,3 @@ res.writeHead(200); | ||
function assertFileParam(route, method) { | ||
var path = '/foo/bar/baz/echo/' + route + '?file=../tests/fixtures/file.json' | ||
var path = '/foo/bar/baz/echo/' + route + '?file=fixtures/file.json', | ||
context = { | ||
@@ -851,3 +855,3 @@ topic: function() { | ||
assert.equal(res.body, file); | ||
} | ||
}; | ||
@@ -854,0 +858,0 @@ return context; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49405
1194