expressjs / serve-static

Serve static files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serve Static Files Case sensitive

sebbi08 opened this issue · comments

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?

it is a OS problem ...

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 :)