Skip to content

Commit

Permalink
(fix) base url is not mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed May 3, 2024
1 parent 2e05d5b commit 7bb3a1a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PUBLIC_GOOGLE_ANALYTICS_ID=
PUBLIC_HOST_URL=http://localhost:3003
PUBLIC_BASE_URL=http://localhost:3003
6 changes: 4 additions & 2 deletions app/frontend/src/components/Article.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---

<div class="mx-auto md:pt-16">
<div class="mx-auto md:pt-16 font-mono">
<p class="text-violet-400 font-bold pb-6 lg:pb-6 text-center text-3xl">
<br />What is <br />
CoverItUp?
Expand Down Expand Up @@ -88,4 +88,6 @@
repositories in an organization.
</div>
</div>
<style></style>
<style>

</style>
2 changes: 1 addition & 1 deletion app/frontend/src/components/LineChart.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!--Main-->
<div
class="container pt-24 md:pt-36 mx-auto flex flex-wrap flex-col md:flex-row items-center"
class="container pt-24 mx-auto flex flex-wrap flex-col md:flex-row items-center"
>
<!--Left Col-->
<div
Expand Down
24 changes: 14 additions & 10 deletions app/frontend/src/components/ReadmeDashboard.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
const hostURL = import.meta.env.PUBLIC_HOST_URL;
const baseURL = import.meta.env.PUBLIC_BASE_URL;
---

<div class="mx-auto" id="data" data-host-url={hostURL}>
<div class="mx-auto" id="data" data-base-url={baseURL}>
<p class="text-violet-400 font-bold text-center text-4xl select-none pt-20">
Embeds
</p>
Expand Down Expand Up @@ -344,21 +344,25 @@ const hostURL = import.meta.env.PUBLIC_HOST_URL;
location.reload();
};

let hostURL = "";
const currentURL = window.location.origin;

let hostURLQ = document.querySelector("[data-host-url]");
if (hostURLQ) {
hostURL = hostURLQ.getAttribute("data-host-url");
let baseURL = document
.querySelector("[data-base-url]")
?.getAttribute("data-base-url");

if (!baseURL) {
baseURL = currentURL;
}
if (!hostURL) {
hostURL = window.location.origin;
if (!baseURL.startsWith("http")) {
baseURL = currentURL + baseURL;
}

const urlParams = new URLSearchParams(window.location.search);
const org = urlParams.get("org");
const repo = urlParams.get("repo");
let branch = urlParams.get("branch");
document.getElementById("org-repo-name").innerText = `${org}/${repo}`;
fetch(`${hostURL}/api/readme?org=${org}&repo=${repo}`)
fetch(`${baseURL}/api/readme?org=${org}&repo=${repo}`)
.then((response) => response.json())
.then((data) => {
if (!branch && data.branches.length > 0) {
Expand All @@ -370,7 +374,7 @@ const hostURL = import.meta.env.PUBLIC_HOST_URL;
d.org = org;
d.repo = repo;
d.branch = branch;
d.url = hostURL.replace("https://", "").replace("http://", "");
d.url = baseURL.replace("https://", "").replace("http://", "");
});

document
Expand Down
10 changes: 9 additions & 1 deletion app/frontend/src/components/Themes.astro
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@
>
Medium: Revolutionizing code tracking for developers
</a>

<br>
<br>
<br>
<a
class="bg-gradient-to-l from-yellow-300 to-yellow-300 text-black font-bold py-2 px-4 rounded focus:ring transform transition hover:scale-105 duration-300 ease-in-out"
type="button"
href="/readme?org=kevincobain2000&repo=gobrew">
See Sample
</a>
</p>
</div>
<style></style>

0 comments on commit 7bb3a1a

Please sign in to comment.