-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Chore: Rewrite dashboard middleware (#178)
* Create draft PR for #177 [skip ci] * Reimplement middleware * Fix packages * Refactor to use dashboardRoute --------- Co-authored-by: Adam Matthiesen <30383579+Adammatthiesen@users.noreply.github.com> Co-authored-by: Jacob Jenkins <7649031+jdtjenkins@users.noreply.github.com> Co-authored-by: Reuben Tier <64310361+TheOtterlord@users.noreply.github.com> Co-authored-by: Paul Valladares <85648028+dreyfus92@users.noreply.github.com>
- Loading branch information
1 parent
8e9d881
commit 73beed8
Showing
5 changed files
with
135 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/studioCMS/src/integrations/studioCMSDashboard/middleware/router.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { MiddlewareHandler } from 'astro'; | ||
import { defineMiddleware, sequence } from 'astro/middleware'; | ||
import micromatch from 'micromatch'; | ||
|
||
export function defineMiddlewareRouter(router: Record<string, MiddlewareHandler>) { | ||
const entries = Object.entries(router); | ||
return defineMiddleware((context, next) => { | ||
return sequence( | ||
...entries | ||
.filter(([path]) => micromatch.isMatch(context.url.pathname, path)) | ||
.map(([_, handler]) => handler) | ||
)(context, next); | ||
}); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters