From decf5687caefc6fdb306264244d92268bff7d8b0 Mon Sep 17 00:00:00 2001 From: NexVeridian Date: Mon, 3 Jun 2024 16:45:04 -0700 Subject: [PATCH] add OVERRIDE_URL --- README.md | 2 ++ src/app/create/create.tsx | 12 +++--------- src/app/create/db.tsx | 5 +++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e8bff19..59f72c4 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ POSTGRES_DB=url # surrealdb DB_USER=root DB_PASSWORD=root + +OVERRIDE_URL=s.nexv.dev ``` # License diff --git a/src/app/create/create.tsx b/src/app/create/create.tsx index 0391ce4..5760fc5 100644 --- a/src/app/create/create.tsx +++ b/src/app/create/create.tsx @@ -46,15 +46,9 @@ export default function CreateCard() { const handleCopyUrl = () => { if (state && state.url) { - const currentSiteName = window.location.hostname; - - let url = undefined; - if (currentSiteName === "localhost" || currentSiteName === "0.0.0.0") { - const currentPort = window.location.port; - url = `http://${currentSiteName}:${currentPort}/${state.url.toString()}`; - } else { - url = `https://${currentSiteName}/${state.url.toString()}`; - } + let url = state.url.includes("https://") + ? state.url + : `http://${window.location.hostname}:${window.location.port}/${state.url.toString()}`; navigator.clipboard.writeText(url) .catch(err => { diff --git a/src/app/create/db.tsx b/src/app/create/db.tsx index 502333c..0266700 100644 --- a/src/app/create/db.tsx +++ b/src/app/create/db.tsx @@ -64,8 +64,13 @@ export async function querydb(prevState: any, formData: FormData) { url = url[0].id; } + console.log(url); + if (process.env.OVERRIDE_URL !== undefined) { + url = `https://${process.env.OVERRIDE_URL}/${url.toString()}`; + } + return { url: url }; } catch (e) { return;