refactor: register plugin routes before the Medusa core routes (#7395)

This commit is contained in:
Harminder Virk
2024-05-22 15:34:53 +05:30
committed by GitHub
parent 2187b82d5d
commit ff5d573887

View File

@@ -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
}