Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Passthrough fails with index: false #10

Closed
wants to merge 3 commits into from

3 participants

@coderarity

Added tests and fixed them.

@pksunkara

@isaacs Can you pull this as soon as possible?

And also consider publishing a new minor version?

@coderarity

This documentation is long overdue. :D

@isaacs isaacs closed this pull request from a commit
@coderarity coderarity Fix passthrough behavior when index:false
close #10

added failing test for passthrough with index: false

fix failing test for passthrough with index: false
2d8c0f1
@isaacs isaacs closed this in 2d8c0f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 7 deletions.
  1. +3 −0  README.md
  2. +3 −0  st.js
  3. +10 −7 test/passthrough.js
View
3  README.md
@@ -44,6 +44,9 @@ var mount = st({
dot: false, // default: return 403 for any url with a dot-file part
dot: true, // allow dot-files to be fetched normally
+
+ passthrough: true, // calls next instead of returning a 404 error
+ passthrough: false, // returns a 404 when a file or an index is not found
})
// with bare node.js
View
3  st.js
@@ -222,6 +222,9 @@ Mount.prototype.serve = function (req, res, next) {
res.setHeader('etag', etag)
if (stat.isDirectory()) {
+ if (this.opt.passthrough === true && this._index === false) {
+ return next();
+ }
return this.index(p, req, res)
}
View
17 test/passthrough.js
@@ -4,7 +4,7 @@ var util = require('util')
var path = require('path')
var opts = util._extend({
- autoindex: true,
+ index: false,
path: path.resolve(__dirname, './fixtures'),
url: '/',
passthrough: true
@@ -21,12 +21,15 @@ test('call next() if passthrough is set', function (t) {
setHeader: function () {},
end: function () {}
}
- t.plan(1)
- function next() {
- t.ok(true, "next called")
- t.end()
- }
- mount(req, res, next)
+ t.plan(2)
+ mount(req, res, function () {
+ t.ok(true, "next called with nonexistant file");
+ req.url='/';
+ mount(req, res, function () {
+ t.ok(true, "next called without indexing")
+ t.end()
+ });
+ })
})
var opts2 = util._extend({
Something went wrong with that request. Please try again.