Skip to content

Commit

Permalink
Fix: subdirectory deployment (#2205)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfchao authored Oct 18, 2023
1 parent 5f7891d commit b8eda91
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 41 deletions.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { i18n } = require("./next-i18next.config");

/** @type {import('next').NextConfig} */
const nextConfig = {
assetPrefix: ".",
reactStrictMode: true,
output: "standalone",
swcMinify: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/services/ping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import useSWR from "swr";

export default function Ping({ group, service, style }) {
const { t } = useTranslation();
const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, {
const { data, error } = useSWR(`api/ping?${new URLSearchParams({ group, service }).toString()}`, {
refreshInterval: 30000
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/services/status.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useSWR from "swr";
export default function Status({ service, style }) {
const { t } = useTranslation();

const { data, error } = useSWR(`/api/docker/status/${service.container}/${service.server || ""}`);
const { data, error } = useSWR(`api/docker/status/${service.container}/${service.server || ""}`);

let statusLabel = t("docker.unknown");
let statusTitle = "";
Expand Down
2 changes: 1 addition & 1 deletion src/components/toggles/revalidate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MdRefresh } from "react-icons/md";

export default function Revalidate() {
const revalidate = () => {
fetch("/api/revalidate").then((res) => {
fetch("api/revalidate").then((res) => {
if (res.ok) {
window.location.reload();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/version.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Version() {
const revision = process.env.NEXT_PUBLIC_REVISION?.length ? process.env.NEXT_PUBLIC_REVISION : "dev";
const version = process.env.NEXT_PUBLIC_VERSION?.length ? process.env.NEXT_PUBLIC_VERSION : "dev";

const { data: releaseData } = useSWR("/api/releases");
const { data: releaseData } = useSWR("api/releases");

// use Intl.DateTimeFormat to format the date
const formatDate = (date) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/glances/glances.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Widget({ options }) {
const { settings } = useContext(SettingsContext);

const { data, error } = useSWR(
`/api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, {
`api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, {
refreshInterval: 1500,
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/kubernetes/kubernetes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Widget({ options }) {
};

const { data, error } = useSWR(
`/api/widgets/kubernetes?${new URLSearchParams({ lang: i18n.language }).toString()}`, {
`api/widgets/kubernetes?${new URLSearchParams({ lang: i18n.language }).toString()}`, {
refreshInterval: 1500
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/longhorn/longhorn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Node from "./node";

export default function Longhorn({ options }) {
const { expanded, total, labels, include, nodes } = options;
const { data, error } = useSWR(`/api/widgets/longhorn`, {
const { data, error } = useSWR(`api/widgets/longhorn`, {
refreshInterval: 1500
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/openmeteo/openmeteo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Widget({ options }) {
const { t } = useTranslation();

const { data, error } = useSWR(
`/api/widgets/openmeteo?${new URLSearchParams({ ...options }).toString()}`
`api/widgets/openmeteo?${new URLSearchParams({ ...options }).toString()}`
);

if (error || data?.error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/openweathermap/weather.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Widget({ options }) {
const { t, i18n } = useTranslation();

const { data, error } = useSWR(
`/api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
`api/widgets/openweathermap?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
);

if (error || data?.cod === 401 || data?.error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/resources/cpu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Error from "../widget/error";
export default function Cpu({ expanded, refresh = 1500 }) {
const { t } = useTranslation();

const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, {
const { data, error } = useSWR(`api/widgets/resources?type=cpu`, {
refreshInterval: refresh,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/resources/cputemp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function convertToFahrenheit(t) {
export default function CpuTemp({ expanded, units, refresh = 1500 }) {
const { t } = useTranslation();

const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, {
const { data, error } = useSWR(`api/widgets/resources?type=cputemp`, {
refreshInterval: refresh,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/resources/disk.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Error from "../widget/error";
export default function Disk({ options, expanded, refresh = 1500 }) {
const { t } = useTranslation();

const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, {
const { data, error } = useSWR(`api/widgets/resources?type=disk&target=${options.disk}`, {
refreshInterval: refresh,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/resources/memory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Error from "../widget/error";
export default function Memory({ expanded, refresh = 1500 }) {
const { t } = useTranslation();

const { data, error } = useSWR(`/api/widgets/resources?type=memory`, {
const { data, error } = useSWR(`api/widgets/resources?type=memory`, {
refreshInterval: refresh,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/resources/uptime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Error from "../widget/error";
export default function Uptime({ refresh = 1500 }) {
const { t } = useTranslation();

const { data, error } = useSWR(`/api/widgets/resources?type=uptime`, {
const { data, error } = useSWR(`api/widgets/resources?type=uptime`, {
refreshInterval: refresh,
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/widgets/weather/weather.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Widget({ options }) {
const { t, i18n } = useTranslation();

const { data, error } = useSWR(
`/api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
`api/widgets/weather?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`
);

if (error || data?.error) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/_document.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default function Document() {
content="A highly customizable homepage (or startpage / application dashboard) with Docker and service API integrations."
/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<link rel="manifest" href="/site.webmanifest?v=4" crossOrigin="use-credentials" />
<link rel="mask-icon" href="/safari-pinned-tab.svg?v=4" color="#1e9cd7" />
<link rel="manifest" href="site.webmanifest?v=4" crossOrigin="use-credentials" />
<link rel="mask-icon" href="safari-pinned-tab.svg?v=4" color="#1e9cd7" />
</Head>
<body>
<Main />
Expand Down
40 changes: 20 additions & 20 deletions src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export async function getStaticProps() {
props: {
initialSettings: settings,
fallback: {
"/api/services": services,
"/api/bookmarks": bookmarks,
"/api/widgets": widgets,
"/api/hash": false,
"api/services": services,
"api/bookmarks": bookmarks,
"api/widgets": widgets,
"api/hash": false,
},
...(await serverSideTranslations(settings.language ?? "en")),
},
Expand All @@ -72,10 +72,10 @@ export async function getStaticProps() {
props: {
initialSettings: {},
fallback: {
"/api/services": [],
"/api/bookmarks": [],
"/api/widgets": [],
"/api/hash": false,
"api/services": [],
"api/bookmarks": [],
"api/widgets": [],
"api/hash": false,
},
...(await serverSideTranslations("en")),
},
Expand All @@ -86,8 +86,8 @@ export async function getStaticProps() {
function Index({ initialSettings, fallback }) {
const windowFocused = useWindowFocus();
const [stale, setStale] = useState(false);
const { data: errorsData } = useSWR("/api/validate");
const { data: hashData, mutate: mutateHash } = useSWR("/api/hash");
const { data: errorsData } = useSWR("api/validate");
const { data: hashData, mutate: mutateHash } = useSWR("api/hash");

useEffect(() => {
if (windowFocused) {
Expand All @@ -108,7 +108,7 @@ function Index({ initialSettings, fallback }) {
setStale(true);
localStorage.setItem("hash", hashData.hash);

fetch("/api/revalidate").then((res) => {
fetch("api/revalidate").then((res) => {
if (res.ok) {
window.location.reload();
}
Expand Down Expand Up @@ -179,9 +179,9 @@ function Home({ initialSettings }) {
setSettings(initialSettings);
}, [initialSettings, setSettings]);

const { data: services } = useSWR("/api/services");
const { data: bookmarks } = useSWR("/api/bookmarks");
const { data: widgets } = useSWR("/api/widgets");
const { data: services } = useSWR("api/services");
const { data: bookmarks } = useSWR("api/bookmarks");
const { data: widgets } = useSWR("api/widgets");

const servicesAndBookmarks = [...services.map(sg => sg.services).flat(), ...bookmarks.map(bg => bg.bookmarks).flat()].filter(i => i?.href);

Expand Down Expand Up @@ -343,25 +343,25 @@ function Home({ initialSettings }) {
</>
) : (
<>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=4" />
<link rel="shortcut icon" href="/homepage.ico" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png?v=4" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png?v=4" />
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png?v=4" />
<link rel="shortcut icon" href="homepage.ico" />
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png?v=4" />
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png?v=4" />
</>
)}
<meta name="msapplication-TileColor" content={themes[settings.color || "slate"][settings.theme || "dark"]} />
<meta name="theme-color" content={themes[settings.color || "slate"][settings.theme || "dark"]} />
</Head>

<link rel="preload" href="/api/config/custom.css" as="fetch" crossOrigin="anonymous" />
<link rel="preload" href="api/config/custom.css" as="fetch" crossOrigin="anonymous" />
<style data-name="custom.css">
<FileContent path="custom.css"
loadingValue="/* Loading custom CSS... */"
errorValue="/* Failed to load custom CSS... */"
emptyValue="/* No custom CSS */"
/>
</style>
<link rel="preload" href="/api/config/custom.js" as="fetch" crossOrigin="anonymous" />
<link rel="preload" href="api/config/custom.js" as="fetch" crossOrigin="anonymous" />
<script data-name="custom.js" src="/api/config/custom.js" async />

<div className="relative container m-auto flex flex-col justify-start z-10 h-full">
Expand Down
4 changes: 2 additions & 2 deletions src/utils/proxy/api-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export function formatProxyUrlWithSegments(widget, endpoint, segments) {
if (segments) {
params.append("segments", JSON.stringify(segments));
}
return `/api/services/proxy?${params.toString()}`;
return `api/services/proxy?${params.toString()}`;
}

export function formatProxyUrl(widget, endpoint, queryParams) {
const params = getURLSearchParams(widget, endpoint);
if (queryParams) {
params.append("query", JSON.stringify(queryParams));
}
return `/api/services/proxy?${params.toString()}`;
return `api/services/proxy?${params.toString()}`;
}

export function asJson(data) {
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/docker/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default function Component({ service }) {
const { widget } = service;

const { data: statusData, error: statusError } = useSWR(
`/api/docker/status/${widget.container}/${widget.server || ""}`
`api/docker/status/${widget.container}/${widget.server || ""}`
);

const { data: statsData, error: statsError } = useSWR(`/api/docker/stats/${widget.container}/${widget.server || ""}`);
const { data: statsData, error: statsError } = useSWR(`api/docker/stats/${widget.container}/${widget.server || ""}`);

if (statsError || statsData?.error || statusError || statusData?.error) {
const finalError = statsError ?? statsData?.error ?? statusError ?? statusData?.error;
Expand Down

0 comments on commit b8eda91

Please sign in to comment.