From 6d31b3f10a05040599e333ff71ad5b112aedce4d Mon Sep 17 00:00:00 2001 From: Jonatan Witoszek Date: Thu, 2 Feb 2023 17:32:07 +0100 Subject: [PATCH] Remove hardcoded URL --- main.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/main.ts b/main.ts index 2e8fe08..bb794fe 100644 --- a/main.ts +++ b/main.ts @@ -15,25 +15,33 @@ interface ActionRequestResponse { } } -const URL = "https://saleor.box.witoszek.dev"; - function getResponse(type: string, amount: string): ActionRequestResponse { - return { - pspReference: `${type}-1234`, - } + // Uncomment for reporting without status update // return { - // pspReference: `${type}-1234`, - // event: { - // type, - // amount, - // message: "Example created by dummy server" - // } + // pspReference: `${type}-1234`, // } + return { + pspReference: `${type}-1234`, + event: { + type, + amount, + message: "Example created by dummy server" + } + } +} + +function getUrl(req: Request) { + const domain = req.headers.get("host"); + if (domain) { + return `https://${domain}`; + } + return "http://localhost:5544" } const routes = [ GET('/', () => Response.OK('Hello, Root')), - GET("/manifest", () => { + GET("/manifest", (req) => { + const URL = getUrl(req); return Response.OK({ id: "witoszekdev.dummy-payment-app", name: "Dummy Payment App",