Node-restify: Static files in subdirectories

Created on 7 Feb 2014  路  4Comments  路  Source: restify/node-restify

Since e6e55e74136ab737a066c10e68e143923b6ca147 I can't access static files from sub directories, only the default index.html works.

server.get(/\/?.*/, restify.serveStatic({
    default: 'index.html',
    directory: './public'
}));

Directory structure is

app.js
    public/
        index.html
        css/
            main.css
Bug

Most helpful comment

For me this is currently the only way to get it working:

server.get(/^\/?.*/, restify.serveStatic({
    directory: __dirname + '/public',
    default: 'index.html'
}));

All 4 comments

For me this is currently the only way to get it working:

server.get(/^\/?.*/, restify.serveStatic({
    directory: __dirname + '/public',
    default: 'index.html'
}));

535

I ran into this issue using version 2.6.1 and was diving in to fix it. But I can't figure out what triggers this bug. I have a really simple test case.

Test file testStatic.js

var restify = require('./lib');
var app = restify.createServer();

app.get(/\/.+/, restify.serveStatic({
  directory: __dirname + '/test/fixtures/folder'
}));

app.listen(8080, function() {
  console.log('Listening at ' + app.name);
});

I run this app from the root of the restify repo. The dir structure looks like this.

   test/
   |-fixtures/
   |---folder/
   |-----index.json
   |-----subfolder/
   |-------index.json

With this setup, I can hit http://localhost/index.json and http://localhost/subfolder/index.json and they both seem to work fine. This works on current master 02210a0, 2.6.2 and 2.6.1. But in the simple app I'm building locally, it doesn't work and I get a ResourceNotFound error. Am I missing something? Is there any clarity on what produces this bug?

I've been working on updating the tests to catch this case. It's been more than trivial because the tests try to create all of the files and then delete them afterwards. This complicates the test files and really isn't necessary for what is being tested. Would you take a PR that changes these to use test fixtures that are checked into repo?

Just released the new version, please check it out!

Was this page helpful?
0 / 5 - 0 ratings