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
Support static files references #137
Conversation
Thanks for your contribution! Linting is failing:
Also, can you add a unit test? |
Yep, I'll fix it. This is still work in progress. I just opened PR so you can track the progress from the beginning :) |
@mcollina are you OK with using |
@kromol I was waiting for this PR to land actually but if it is really necessary I will bump the version |
Which issue? |
I meant this issue - fastify/fastify#1338 Currently the problem is that plugin will have to serve static files from two different locations:
With current setup I initially was thinking about adding additional regex route to handle only yaml and json files and do not break other static stuff handled by But I just realized that another way might be to put everything served by |
53683e2
to
5deeadf
Compare
Happy New Year! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd also need to add the new option to the type definition in https://github.com/fastify/fastify-swagger/blob/master/index.d.ts#L10 and a test for the typescript types.
t.error(err) | ||
t.strictEqual(res.statusCode, 404) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a test that checks that the Fastify not found handler is called? This is likely to fail/conflict on Fastify v2, and we need the test to make sure the behavior is consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
routes.js
Outdated
const contentType = ext === '.yaml' ? 'application/x-yaml' : 'application/json' | ||
reply | ||
.type(contentType) | ||
.send(fs.readFileSync(filePath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better if you switch to fastify-static reply.sendFile()
method. You can just add the decorator by passing { serve: false }
when registering fastify-static.
You'll need to register two instances of fastify-static, one with { serve: false }
to use inside this function, and one with { decorateReply: false }
to serve the swagger-ui. The two instances should not conflict/error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Resolves issue fastify#134
…ileSync, added more tests, fixed docs, updated typings, ensure that custom NotFoundHandler is being called
5bd339e
to
4ee6535
Compare
Rebased my branch on the latest |
@kromol you dont need to squash |
Ok, great. I just thought that it should eventually be one commit per issue to keep history clean. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
routes.js
Outdated
decorateReply: false | ||
}) | ||
|
||
fastify.register(require('fastify-static'), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: You should probably move the require('fastify-static')
at the top of the file in both instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, done.
Since we added prefix `/static` to separate swagger ui static files from other files we need to make sure that client wlll not use `/static` prefix for other calls (like for retrieving swagger.yaml)
Since we added prefix `/static` to separate swagger ui static files from other files we need to make sure that client wlll not use `/static` prefix for other calls (like for retrieving swagger.yaml)
No description provided.