From 058a1361f2a5d017a0bd103be3940625ef4e0d01 Mon Sep 17 00:00:00 2001 From: child_duckling <19170969+child-duckling@users.noreply.github.com> Date: Mon, 28 Jun 2021 19:55:25 -0700 Subject: [PATCH] If NEXT_PUBLIC_PROJECT_URL is not set, default to host URL If NEXT_PUBLIC_PROJECT_URL is not set, default to the URL where the page is being hosted. This will be useful if people use the Railway button cause there is know way to default to the given *.up.railway.app url beforehand. This worked in my crude test. --- pages/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pages/index.js b/pages/index.js index 60cc53f..e8d9999 100644 --- a/pages/index.js +++ b/pages/index.js @@ -14,6 +14,7 @@ import { import { MoonIcon, SunIcon, CopyIcon, CheckCircleIcon } from "@chakra-ui/icons"; import { useRef, useEffect, useState } from "react"; export default function Home() { + if (process.env.NEXT_PUBLIC_PROJECT_URL == ""){const base = document.URL} else {const base = process.env.NEXT_PUBLIC_PROJECT_URL} //If ENV var is not set, default to host URL const [linkValue, setLinkValue] = useState(""); const { toggleColorMode } = useColorMode(); const toast = useToast(); @@ -44,11 +45,11 @@ export default function Home() { }); return; } else if (short_link) - setLinkValue(`${process.env.NEXT_PUBLIC_PROJECT_URL}/${short_link}`); + setLinkValue(`${base}/${short_link}`); linkInputRef.current.value = ""; toast({ title: "Link created.", - description: `Your link is ready at ${process.env.NEXT_PUBLIC_PROJECT_URL}/${short_link}`, + description: `Your link is ready at ${base}/${short_link}`, status: "success", duration: 5000, isClosable: true,