Skip to content
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

Merged
merged 5 commits into from
Dec 6, 2019

Conversation

PatrickHeneise
Copy link
Contributor

@PatrickHeneise PatrickHeneise commented Dec 6, 2019

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

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

@PatrickHeneise PatrickHeneise changed the title Automatically wrap full routes into fastify plugins. Closes #54 Automatically wrap full routes into fastify plugins Dec 6, 2019
Copy link
Member

@mcollina mcollina left a 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?

@PatrickHeneise
Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

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')

?

Copy link
Member

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.

Copy link
Contributor Author

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.

index.js Outdated Show resolved Hide resolved
Co-Authored-By: James Sumners <[email protected]>
Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit d25614d into fastify:master Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically wrap route files
3 participants