Skip to content

Commit

Permalink
fix: issues with routes prefixed with /admin/store to break (#103)
Browse files Browse the repository at this point in the history
* fix issue with paths being replaced, causing issues with route /admin/store

* chore: cleanup
  • Loading branch information
dwene authored Jul 27, 2022
1 parent fca67d1 commit f913ae5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
20 changes: 6 additions & 14 deletions src/loaders/admin-api.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,18 @@ export async function adminApiLoader(
const adminMiddlewares = middlewares
.map((middleware) => ({
...middleware,
routes: middleware.routes.filter((route) => {
if (route.path.startsWith('/admin')) {
route.path = route.path.replace('/admin', '');
return true;
}
return false;
}),
routes: middleware.routes
.filter((route) => route.path.startsWith('/admin'))
.map((route) => ({ ...route, path: route.path.replace('/admin', '') })),
}))
.filter((middleware) => middleware.routes.length);

const adminRouters = routers
.map((router) => ({
...router,
routes: router.routes.filter((route) => {
if (route.path.startsWith('/admin')) {
route.path = route.path.replace('/admin', '');
return true;
}
return false;
}),
routes: router.routes
.filter((route) => route.path.startsWith('/admin'))
.map((route) => ({ ...route, path: route.path.replace('/admin', '') })),
}))
.filter((route) => route.routes.length);

Expand Down
20 changes: 6 additions & 14 deletions src/loaders/store-api.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,18 @@ export async function storeApiLoader(
const storeMiddlewares = middlewares
.map((middleware) => ({
...middleware,
routes: middleware.routes.filter((route) => {
if (route.path.startsWith('/store')) {
route.path = route.path.replace('/store', '');
return true;
}
return false;
}),
routes: middleware.routes
.filter((route) => route.path.startsWith('/store'))
.map((route) => ({ ...route, path: route.path.replace('/store', '') })),
}))
.filter((middleware) => middleware.routes.length);

const storeRouters = routers
.map((router) => ({
...router,
routes: router.routes.filter((route) => {
if (route.path.startsWith('/store')) {
route.path = route.path.replace('/store', '');
return true;
}
return false;
}),
routes: router.routes
.filter((route) => route.path.startsWith('/store'))
.map((route) => ({ ...route, path: route.path.replace('/store', '') })),
}))
.filter((route) => route.routes.length);

Expand Down

0 comments on commit f913ae5

Please sign in to comment.