Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

When route is not '/', req.url that is not trailing '/' causes incorrect response. #445

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants

luuvish commented Dec 22, 2011

server = connect.createServer();
server.use('/any-path', connect.static(__dirname + '/public'));

When req.url is 'http://any-domain/any-path',
static middleware will response with 'http://any-domain/any-path/index.html'.

But the request of web browser is '/any-path', not '/any-path/'. the browser mis-guesses the path of request is '/', not '/any-path/'.

In case of routes is not '/', the request URL that is not trailing '/…
…' causes mis-response by static middleware.

the URL that is directory without trailing '/' must not be added to '/index.html', must be redirect to correct path.

valette commented Jul 31, 2012

+1 for this old issue

One strange thing is that http://any-domain/any-path/subdir is redirected to http://any-domain/any-path/subdir/

but http://any-domain/any-path is not

I tried the proposed patch, and it seems to work. Are there any undesirable side-effects?

Thanks

valette commented Sep 7, 2012

bumping this issue with a self-contained example:

var fs      = require('fs'),
    connect = require('connect');

var app=connect();
var dataDir='data';
var subFolder=dataDir+'/subfolder';

if (!fs.existsSync(dataDir)) {
    fs.mkdirSync(dataDir);
    if (!fs.existsSync(subFolder)) {
        fs.mkdirSync(subFolder);
    }
}

var htmlFile='<html><head><script src="subfolder/canvas.js"></script></head><body><canvas name="canvas" width="500" height="400"></canvas></body></html>';
fs.writeFileSync(dataDir+'/index.html', htmlFile);

var jsFile='function draw() {var canvas = document.getElementsByName("canvas")[0];var ctx = canvas.getContext("2d");ctx.fillStyle = "rgb(0,500,0)";ctx.fillRect (50, 50, 200, 200);}window.onload=draw';
fs.writeFileSync(subFolder+'/canvas.js', jsFile);

// serve data files. this one does not work correctly
app.use('/test', connect.static(dataDir));
app.listen(8080);

accessing to
http://localhost:8080/test/
shows a green rectangle, but accessing
http://localhost:8080/test
does not work the same way.

@ghost ghost assigned tj Sep 26, 2013

Contributor

dougwilson commented Oct 18, 2013

@jonathanong this was fixed long ago in the static middleware. This can be closed.

Contributor

jonathanong commented Oct 18, 2013

valette commented Oct 18, 2013

Sorry, but I just tried again the minimal test case provided above, and I still have the same behavior. Am I missing something here?

Contributor

dougwilson commented Oct 18, 2013

@valette I didn't understand what the OP was really talking about, but I re-read your comment below that and I believe I know what you are saying now. I'll check it out and whip up a patch (this patch fixes it in the wrong place, because having a trailing / is actually meant to be optional for routing, though I can see whanting it for the static middleware). @jonathanong I suppose reopen this?

@jonathanong jonathanong reopened this Oct 18, 2013

@jonathanong jonathanong closed this in #937 Oct 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment