refactor: register plugin routes before the Medusa core routes (#7395)
This commit is contained in:
@@ -28,6 +28,28 @@ export default async ({ app, container, plugins }: Options) => {
|
||||
ContainerRegistrationKeys.CONFIG_MODULE
|
||||
)
|
||||
|
||||
/**
|
||||
* Always load plugin routes before the Medusa core routes, since it
|
||||
* will allow the plugin to define routes with higher priority
|
||||
* than Medusa. Here are couple of examples.
|
||||
*
|
||||
* - Plugin registers a route called "/products/active"
|
||||
* - Medusa registers a route called "/products/:id"
|
||||
*
|
||||
* Now, if Medusa routes gets registered first, then the "/products/active"
|
||||
* route will never be resolved, because it will be handled by the
|
||||
* "/products/:id" route.
|
||||
*/
|
||||
await Promise.all(
|
||||
plugins.map(async (pluginDetails) => {
|
||||
return new RoutesLoader({
|
||||
app: app,
|
||||
configModule,
|
||||
rootDir: path.join(pluginDetails.resolve, "api"),
|
||||
}).load()
|
||||
})
|
||||
)
|
||||
|
||||
// TODO: Figure out why this is causing issues with test when placed inside ./api.ts
|
||||
// Adding this here temporarily
|
||||
// Test: (packages/medusa/src/api/routes/admin/currencies/update-currency.ts)
|
||||
@@ -47,15 +69,5 @@ export default async ({ app, container, plugins }: Options) => {
|
||||
)
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
plugins.map(async (pluginDetails) => {
|
||||
return new RoutesLoader({
|
||||
app: app,
|
||||
configModule,
|
||||
rootDir: path.join(pluginDetails.resolve, "api"),
|
||||
}).load()
|
||||
})
|
||||
)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user