restify/node-restify

Restify.plugins.serverStatic option "appendRequestPath" is bugged

Open

#1604 aperta il 11 feb 2018

Vedi su GitHub
 (16 commenti) (1 reazione) (0 assegnatari)JavaScript (983 fork)batch import
BugGood First IssueServe

Metriche repository

Star
 (10.695 star)
Metriche merge PR
 (Merge medio 3h 56m) (2 PR mergiate in 30 g)

Descrizione

  • [ X ] Used appropriate template for the issue type
  • [ X ] Searched both open and closed issues for duplicates of this issue
  • [ X ] Title adequately and concisely reflects the feature or the bug

Bug Report

Restify.plugins.serverStatic option "appendRequestPath" is not working properly.

Restify Version

v6.3.4

Node.js Version

v8.91

Expected behaviour

I expected appendRequestPath = false; to make it so that the request path is not appended to the file path. (As stated in the documentation at http://restify.com/docs/plugins-api/#servestatic)

Actual behaviour

The request path was appended to the file path, despite the fact that appendRequestPath was set to false.

Repro case

index.js

var restify = require('restify');

const server = restify.createServer({
    name: 'myapp',
    version: '1.0.0'
  });

server.get('/endpoint', restify.plugins.serveStatic({
    directory: __dirname, // dirname is /Users/keithlee96/testFolder/test-api
    default: 'index.html',
    appendRequestPath: false
}));

server.listen(9090, function(){
    console.log('%s listening at %s', server.name, server.url);
});

index.html was in the same folder.

I ran the file with node index.js When I made a get request to localhost:9090/endpoint in postman, I got the error:

{
    "code": "ResourceNotFound",
    "message": "/endpoint; caused by Error: ENOENT: no such file or directory, stat '/Users/keithlee96/testFolder/test-api/endpoint'"
}

Expected the targeted file path to be: '/Users/keithlee96/testFolder/test-api/index.html'

Are you willing and able to fix this?

No, I'm no familiar with typescript, so I don't know how to fix the error myself. I just want it to behave as the documentation http://restify.com/docs/plugins-api/#servestatic says it should. Any help on this would be greatly appreciated.

Guida contributor