-
Notifications
You must be signed in to change notification settings - Fork 982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restify.plugins.serverStatic option "appendRequestPath" is bugged #1604
Comments
I agree, just met the same unexpected behaviour. Why it is there? I assume it has little sense. Regards, |
Hey @keithlee96, First, thank you for the thorough bug report with detailed examples ❤️. Currently the As it stands, I wouldn't recommend using this plugin and instead would recommend either:
|
serveStatic keeps coming up again and again, but it doesn't seem like we ever get momentum on fixing this plugin. Would it be worth considering removing it from our plugins? Having it in a half-working state is causing confusion. |
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! |
@kingnebby sorry this was such a painful experience for you. I believe we should deprecate this unless someone is willing to step-up and maintain this plugin. Based on the activity I've seen on this since I've joined the project, I suspect there is a low probability of this becoming actively maintained so my vote is to deprecate it entirely with a note about alternative solutions. |
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. |
@retrohacker - I can't complain tbh, this and many other projects have saved me probably trillions of hours of work. :) Also, I think providing a guide on the 'fs' option is better than telling people to use NGinx. Idk, it feels wrong to say, "Just go use a different technology to configure your server" as a solution to a framework shortcoming. As far as swagger goes, that might be a good use case/tutorial. I finally got it all working with some funkiness:
Wired with this code. // Serve the swagger-ui pages.
server.get(/\/doc\/.*/, restify.plugins.serveStatic({
directory: './dist',
default: 'index.html',
}))
// Serves just the Swagger spec for various consumption, like
// the Swagger-UI, and the online Swagger-Editor.
server.get(/^\/swagger$/, restify.plugins.serveStatic({
directory: './dist',
file: 'swagger.yaml',
}))
// Helper to reroute people who don't type exaclty the write URL.
server.get(/(^\/$|^\/doc$)/, (req, res, next) => {
res.redirect('/doc/', next)
}) Who knows, maybe this will help someone. |
Ouch. Me too. Hitting this issue. I really like |
@kingnebby can you provide a more detailed example of the swagger configuration? I've been trying to add swagger documentation to my restify api with no luck. Thanks in advance!! |
@irokhes I was actually considering doing a full tutorial, this is a good incentive :) Maybe I'll try to put it on Medium next week. |
@kingnebby that would be awesome! Thanks! |
Hey, do you know, when/If this will be fixed at all? If Not, I would really appreciate a deprecation msg. Cheers and thx |
Hi! I would like to contribute to this project!
The PR will be serving index.html which is located on __dirname, and it will not try to search it on __dirname/endpoint. I hope this helps you guys, please let me know any feedback! |
See #1910 |
Fixes restify#1604 There should be no dependency on the dirname for specific path.
plugins.serveStatic Fixes restifyGH-1604
Error still exists in last restify version 11.1.0. Example: server.get(
"/doc/*",
restify.plugins.serveStatic({
directory:"./api-doc",
default: "index.html",
maxAge: 1,
appendRequestPath: false
})
); Access to /doc/ produce error:
Access to /doc/index.html works |
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
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:
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.
The text was updated successfully, but these errors were encountered: