cloudhead / node-static

rfc 2616 compliant HTTP static-file server module, with built-in caching.
MIT License
2.17k stars 245 forks source link

no file extension, application/octet-stream #169

Open stevenvachon opened 8 years ago

stevenvachon commented 8 years ago

Files with no extension are served with content-type "application/octet-stream" due to https://www.npmjs.com/package/mime#mime-default-type

Shouldn't they just be undefined?:

mime.default_type = undefined
stevenvachon commented 8 years ago

Could also switch away from "mime" package to https://github.com/Hypercubed/mime-lookup

stevenvachon commented 8 years ago

Hello?

stevenvachon commented 8 years ago

Forget it.

Switching to st fixed this issue.

CezaryDanielNowak commented 8 years ago

I had the same issue, and solved it by:

var SERVER_PATH = './dist';
var SERVER_PORT = 8080;

function runServer() {
  var file = new static.Server(SERVER_PATH);
  require('http').createServer(function (request, response) {
    request.addListener('end', function () {
      // check if last part of address has extension, if not serve html
      if (request.url.split('/').pop().indexOf('.') === -1) {
        file.serveFile(request.url, 200, {'Content-Type': 'text/html'}, request, response);
      } else {
        file.serve(request, response);
      }
    }).resume();
  }).listen(SERVER_PORT);
}
CezaryDanielNowak commented 8 years ago

@cloudhead, file.serve(...) should really have some way to manipulate headers :-)

stevenvachon commented 8 years ago

Everything that this library does, st does better.

leviwheatcroft commented 7 years ago

PR #184 would allow something like this:

var file = new static.Server('./public');

require('http').createServer(function (request, response) {
    request.addListener('end', function () {
        response.setHeader('Content-Type', 'text/html') // explicitly override header here
        file.serve(request, response);
    }).resume();
}).listen(8080);