0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/server/services/routing
kirrg001 691daa2a49 ParentRouter: Added wrapper for Express Router
refs #9601

- if you call `express.Router()`, the router's name is always "router"
- that is caused by the closure behaviour in express:
  - https://github.com/expressjs/express/blob/4.16.3/lib/router/index.js#L46
- Ghost creates a couple of express routers for dynamic routing
  - it depends how much you configure in your routes.yaml file
  - but every router is called "router"
  - this is hard to work with
- with this router wrapping logic, we are able to give each router an exact name

If you enable `DEBUG=ghost:services:routing:*`, you have seen this before

> ghost:services:routing:ParentRouter site: mountRouter: router +0ms

With the wrapper logic, you will see:

> ghost:services:routing:ParentRouter site: mountRouter: StaticPagesRouter +0ms

- furthermore, if you have to access the router stack (`app.router.stack`), you can easily identify and find router instances by name
2018-06-13 21:22:10 +02:00
..
controllers 🐛 Fixed preview url and Zapier on subdirectory (#9683) 2018-06-12 16:36:58 +01:00
helpers 🐛 Fixed slug template for tags and authors 2018-06-11 22:06:47 +02:00
middlewares
bootstrap.js
CollectionRouter.js 🐛 Fixed default theme context 2018-06-08 15:11:47 +02:00
index.js
ParentRouter.js ParentRouter: Added wrapper for Express Router 2018-06-13 21:22:10 +02:00
PreviewRouter.js
registry.js
RSSRouter.js
StaticPagesRouter.js
StaticRoutesRouter.js
TaxonomyRouter.js