From 3645dc5c5fc3d9da24c54dda5a4a2d96d100d623 Mon Sep 17 00:00:00 2001 From: Joshua Date: Sun, 18 Sep 2022 15:07:41 +0200 Subject: [PATCH] Add Domain middleware --- utils/middleware/domain.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 utils/middleware/domain.ts diff --git a/utils/middleware/domain.ts b/utils/middleware/domain.ts new file mode 100644 index 0000000..162286d --- /dev/null +++ b/utils/middleware/domain.ts @@ -0,0 +1,15 @@ +import { pogo } from "../../deps.ts" +interface RequestParameters { r: pogo.Request, h: pogo.Toolkit } + +export default ({ r, h }: RequestParameters, domains: string[] | string, handler: any) => { + if (domains.includes(r.host) || domains.includes("*")) { + console.log("Call actual Handler") + return handler(r, h) + + } else { + console.log("Throw Error") + return h.response({ + error: "This Site/Fuction doesn't exist or is not available on the current domain." + }).code(404) + } +} \ No newline at end of file