-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Automatically wrap full routes into fastify plugins #57
Conversation
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.
Good work, would you mind to add some docs for this?
Absolutely not. Wanted to get some feedback and wrap up the code & tests first. Docs are coming in a moment. |
index.js
Outdated
const content = require(file) | ||
let plugin | ||
|
||
if (content && typeof content === 'object' && content.method) { |
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.
This check for object-ness is not suffcient. An array will pass this check. You should Object.prototoype.toString.apply(content) === true
.
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.
What do you think of:
Object.prototype.toString.apply(content) === '[object Object]' &&
Object.prototype.hasOwnProperty.call(content, 'method')
?
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.
Yes, that's what I meant 🤦♂. It's still early morning for me over here.
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.
No worries :) thanks for the hint. I thought about that before but then though this might be already sufficient but you're right. Adding both checks now.
Co-Authored-By: James Sumners <[email protected]>
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
Closes #54
The idea is to reduce the routing files to just the route schema, without wrapping everything into a fastify plugin in every file. It's a cosmetic change.
I'm missing the docs part. Let me know if everything is good to go, then I'll add the part to the README.
Checklist
npm run test
andnpm run benchmark