Skip to content

Commit

Permalink
fix: dynamic pathname for github
Browse files Browse the repository at this point in the history
  • Loading branch information
Boutzi committed Oct 12, 2024
1 parent 479194c commit 8ad10e9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/_components/VersionStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
"use client";
import { useEffect, useState } from 'react';
import { useEffect, useState } from "react";

const VersionStatus = () => {
const [version, setVersion] = useState<string>();

useEffect(() => {
const location = window.location;
console.log(location)
let basePath: string;

if (location.href.includes("boutzi.github.io")) {
basePath = `${location.origin}/oc-integrateur-web`;
} else {
basePath = location.origin;
}

console.log("Base Path:", basePath);

const fetchVersion = async () => {
try {
const response = await fetch(`${location.origin}/api/version`);
Expand All @@ -16,16 +25,14 @@ const VersionStatus = () => {
const data = await response.json();
setVersion(data.version);
} catch (error) {
console.error('Failed to fetch version:', error);
console.error("Failed to fetch version:", error);
}
};

fetchVersion();
}, []);

return (
<span>{version ? version : "---"}</span>
);
return <span>{version ? version : "---"}</span>;
};

export default VersionStatus;

0 comments on commit 8ad10e9

Please sign in to comment.