expressjs / serve-static

Serve static files
MIT License
1.38k stars 227 forks source link

Serve Static Files Case sensitive #93

Closed sebbi08 closed 7 years ago

sebbi08 commented 7 years ago

Hi i have the following server

(function() {
  'use strict';
  var express = require('express');
  var serveStatic = require('serve-static');
  var serveIndex = require('serve-index');
  var finalhandler = require('finalhandler');
  var open = require('opn');

  var app = express();
  var router = express.Router({
    caseSensitive: true
  });
  var index = serveIndex(__dirname, {
    'icons': true
  })
  var serve = serveStatic(__dirname, { // eslint-disable-line
    dotfiles: 'allow',
    setHeaders: setHeaders
  });

  function setHeaders(res, path) {
    res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
    res.header('Expires', '-1');
    res.header('Pragma', 'no-cache');
  }

  router.use(index);
  router.use(serve);
  app.use(router);

  var port = 8080;

  app.listen(port, function() {
    console.log("server is now running on http://127.0.0.1:" + port); // eslint-disable-line
    open("http://localhost:" + port);
  });
}());

but it is still serving the static files case insensitiv.

is there any way to get them served case sensitive? is it maybe a OS problem because i am using Mac osx?

sebbi08 commented 7 years ago

it is a OS problem ...

dougwilson commented 7 years ago

Hi @sebbi08 yea, since under the hood the files names are from the URL, even though we preserve the case, if the underlying file system stat and open still come back, the file will end up getting served. There may be some kind of complex work-around to open a file and get the name based on the file descriptor and then validate that it is a case-sensitive match to what was in the URL, I'm not sure. If you know a way to implement this as an option, please feel free to make a pull request :)