node-restify: Restify.plugins.serverStatic option "appendRequestPath" is bugged
- [ 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.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
Commits related to this issue
- fix(GH-1604): plugins.serveStatic no dep dirname Fixes https://github.com/restify/node-restify/issues/1604 There should be no dependency on the dirname for specific path. — committed to kolbma/node-restify by kolbma 2 years ago
- Merge pull request #2 from kolbma/GH-1604 plugins.serveStatic Fixes GH-1604 — committed to kolbma/node-restify by kolbma 2 years ago
Agree, just battled with this for longer than I should have since I was trusting the documentation. All I was trying to do was connect a Swagger-UI documentation feature to my rest api.
Please either deprecate or provide good advice for alternatives. Thanks!
Hi! I would like to contribute to this project! I created PR: https://github.com/restify/node-restify/pull/1860 that attempts to fix this issue. With that PR now Restify.plugins.serverStatic will behave as in the documentation http://restify.com/docs/plugins-api/#servestatic when appendRequestPath is set to false. For the example code above:
The PR will be serving index.html which is located on __dirname, and it will not try to search it on __dirname/endpoint. Also this applies for any resource, not only to retrieve the default. i.e: /endpoint/anotherResourse.html will serve __dirname/anotherResource.html in we set:
server.get('/endpoint/*, ...
I hope this helps you guys, please let me know any feedback!
Hey,
do you know, when/If this will be fixed at all?
If Not, I would really appreciate a deprecation msg.
Cheers and thx
I’m okay with removing this as it’s a REST framework, however, may some user want to serve Swagger spec as a static file.