Node static directory case sensitive

217 views
Skip to first unread message

dan krutz

unread,
May 30, 2015, 5:42:16 PM5/30/15
to nod...@googlegroups.com
I have a plain old html file within a static directory running under public. When a user hits server.com/caa/ I'd like to serve up the static html page. However, if they user also goes to server.com/CAA/ I'd like them to go to the same directory, so case sensitivity should not matter. Right now, when the user enters in a capital "CAA" they visit a different folder than a lowercase "caa" ... I'd like this not to be the case.

Can anyone tell me where I can fix this inside node? I am a node newbie.

Thanks all.

Ryan Schmidt

unread,
May 30, 2015, 10:59:22 PM5/30/15
to nod...@googlegroups.com

On May 30, 2015, at 1:26 AM, dan krutz wrote:

> I have a plain old html file within a static directory running under public. When a user hits server.com/caa/ I'd like to serve up the static html page. However, if they user also goes to server.com/CAA/ I'd like them to go to the same directory, so case sensitivity should not matter. Right now, when the user enters in a capital "CAA" they visit a different folder than a lowercase "caa" ... I'd like this not to be the case.
>
> Can anyone tell me where I can fix this inside node? I am a node newbie.

You probably shouldn't do that. URLs are assumed to be case-sensitive, and each resource should be available by a single canonical URL. The same resource should not be served from additional URLs (regardless whether those differ from the canonical URL in case, hostname, or other details) unless they do so by issuing an HTTP 301 redirect to the canonical URL. (I guess the one exception to that is that it is ok to serve the same resource at two different URLs that differ in protocol -- http vs. https -- since there are valid reasons to want that.)

Eiríkur

unread,
May 31, 2015, 4:51:49 PM5/31/15
to nod...@googlegroups.com
This is a good use case for a symbolic link in the file system. 

Ryan Graham

unread,
May 31, 2015, 5:32:37 PM5/31/15
to nod...@googlegroups.com
A symlink for this won't work out well if you do development on Mac and/or Windows, since they default to using case-insensitive/case-folding filesystems. This gets doubly annoying if you are using git, since it is case-sensitive, even if the underlying filesystem is not.

~Ryan

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/f25dadff-0550-4b01-83ca-7952786be33e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joshua Holbrook

unread,
May 31, 2015, 9:43:33 PM5/31/15
to nod...@googlegroups.com
How are you hosting these static files?

My guess is that the usual suspects in terms of static file serving in
pure node---ie, express static, hapi static and ecstatic, do not have
built-in support for this kind of thing (I can confirm this in the
case of ecstatic). If you really really need this you might be able to
hack it in by adding functionality that somehow does lookups against
filename.toLowerCase() versions of whatever you're looking for, but
this is likely non-trivial.

Another option, if you're hosting static files with nginx (a good idea
for production) is to see if nginx has support for this (my guess is
not).

Like has already been suggested, symlinks should work on a
case-sensitive filesystem such as what you'd see on linux, but will
cause a world of hurt on case-insensitive filesystems like with osx.

Honestly, the easiest thing for you is to probably decide this
behavior isn't crucial and leave it be. Note that this is different
from "you don't want this," rather what I'm saying is more, "you
probably don't want this *bad enough* to go through the trouble." :)

--Josh
> https://groups.google.com/d/msgid/nodejs/CAGjmZGw1eFcoiYLXAdynytckOEkE3YkcTD1Zk%2B8OG_v2Cyiitw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages