Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Prefixing recursive routes #3

Open
Liumkattan opened this issue Apr 27, 2020 · 1 comment
Open

Prefixing recursive routes #3

Liumkattan opened this issue Apr 27, 2020 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Liumkattan
Copy link

Liumkattan commented Apr 27, 2020

It will be much convenient to be able to prefix a recursive route instead to have to write the whole path for each endpoint:

// /server/routes/index.js
export default ({ fastify, self }) => {
    // Being able to register recursive routes s plugins for example
    fastify.register(require("./v1"), { prefix: "/v1" });
    fastify.register(require("./v2"), { prefix: "/v2" });
};

So the recursive routes can be written "relatively" not "absolutely"

// /server/routes/v1/index.js
export default ({ fastify, self }) => {
  fastify.get("/", self.name); // points to /api/v1/
  // Instead of this
  // fastify.get("/v1", self.name);
  // providing the whole path, which will become much longer with more folders recursively 
};

PS:

  • This example is based on the default example
  • I tried this method hoping register would work but it did not.

Thank you

@galvez galvez added enhancement New feature or request help wanted Extra attention is needed labels Apr 27, 2020
@galvez
Copy link
Owner

galvez commented Apr 27, 2020

Hi @Liumkattan that'd be very nice indeed. This last PR of mine paves the way for implementing this by introducing getFastifyFacade(). I don't have the time to do it right now unfortunately, but welcome any attempts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants