Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Redirecting to // - connect.static bug on Windows #427

Closed
alessioalex opened this Issue · 8 comments

7 participants

@alessioalex

When using connect.static on Windows (with Express), when visiting http://localhost it will show you:

Redirecting to //

even though you have the '/' route defined. I managed to find a workaround for this by using 'redirect: false' as an option, but this is a bug as far as I can tell (on Linux I never got that).

Note: I did not have anything except a txt file in the public folder. (so no index.html there)

@tj
Owner
tj commented

thanks i'll add a test case for this in a bit and get it covered

@andihit

Same problem here, but in my case, I have an index.html.
I investigated a bit, and the issue lies in this line:

if ('/' == path[path.length - 1]) path += 'index.html';

in lib/middleware/static.js.
Because node's path.join uses \ on windows, we'll need an check like this

var pathsep = process.platform === 'win32' ? '\\' : '/';
if (pathsep == path[path.length - 1]) path += 'index.html';
@mojodna

+1 on @andihit's fix.

@mojodna

Cleaner:

if (normalize('/') == path[path.length - 1]) path += 'index.html';
@hdf

Yes, this bug has been bothering me for months now.
+1 on @mojodna -s fix.

@tj tj closed this in b74a338
@tj
Owner
tj commented

sorry for the delay i've been sick, i'll push a new release

@keichii

this is wrong... please adjust
if (normalize('/') == path[path.length - 1]) path += 'index.html';

to:

if (normalize('/') == normalize(path[path.length - 1])) path += 'index.html';

broked all the frameworks who used this:

railwayjs
express
etc..

it fixed this bug on windows.

@oluwie

This fix works on all browsers for me except for Chrome.

Any ideas????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.