feat: layered and scoped middleware and context state (#139)
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
co-authored by
Luca Casonato
parent
b36f2c1a43
commit
8d4e77f4ac
@@ -0,0 +1,24 @@
|
||||
import { assert } from "../../tests/deps.ts";
|
||||
import { middlewarePathToPattern, selectMiddlewares } from "./context.ts";
|
||||
import { MiddlewareRoute } from "./types.ts";
|
||||
|
||||
Deno.test("selectMiddlewares", () => {
|
||||
const url = "https://fresh.deno.dev/api/abc/def";
|
||||
const middlewaresPath = [
|
||||
// should select
|
||||
"_middleware",
|
||||
"api/_middleware",
|
||||
"api/[id]/_middleware",
|
||||
|
||||
// should not select
|
||||
"api/xyz/_middleware",
|
||||
"api/[id]/xyz/_middleware",
|
||||
"api/[id]/[path]/_middleware",
|
||||
"api/[id]/[path]/foo/_middleware",
|
||||
];
|
||||
const mwRoutes = middlewaresPath.map((path) =>
|
||||
middlewarePathToPattern(path)
|
||||
) as MiddlewareRoute[];
|
||||
const mws = selectMiddlewares(url, mwRoutes);
|
||||
assert(mws.length === 3);
|
||||
});
|
||||
Reference in New Issue
Block a user