From e72450f0af1de4b3dffc57328cd335539aee326d Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 5 Jul 2024 16:37:06 +0200 Subject: [PATCH] fix doc redirects --- deploy/kv/manual/index.md | 6 +++--- server.ts | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/deploy/kv/manual/index.md b/deploy/kv/manual/index.md index c33918e84..2fcad9cd2 100644 --- a/deploy/kv/manual/index.md +++ b/deploy/kv/manual/index.md @@ -1,9 +1,9 @@ --- title: "Deno KV Quick Start" oldUrl: - - /kv - - /kv/manual - - /runtime/manual/runtime/kv + - /kv/ + - /kv/manual/ + - /runtime/manual/runtime/kv/ --- **Deno KV** is a diff --git a/server.ts b/server.ts index 45d732a96..c63a61d31 100644 --- a/server.ts +++ b/server.ts @@ -1,5 +1,4 @@ import Server from "lume/core/server.ts"; -import redirects from "lume/middlewares/redirects.ts"; import REDIRECTS from "./_redirects.json" with { type: "json" }; const server = new Server({ @@ -7,12 +6,22 @@ const server = new Server({ root: ".", }); -server.use(redirects({ - redirects: { - ...REDIRECTS, - "/api/": "/api/deno/", - }, -})); +REDIRECTS["/api/"] = "/api/deno/"; + +server.use(async (req, next) => { + const url = new URL(req.url, "http://localhost:8000"); + const redirect = REDIRECTS[url.pathname] || REDIRECTS[url.pathname + "/"]; + if (redirect) { + return new Response(null, { + status: 301, + headers: { + "Location": redirect, + }, + }); + } else { + return await next(req); + } +}); server.start();