Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable basepath #109

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ FROM nginx:alpine
# Copy the nginx configuration
COPY ./docker/default.conf.template /etc/nginx/templates/default.conf.template

# Copy the entrypoint substitution script
COPY ./docker/configure.sh /docker-entrypoint.d/99-configure.sh
RUN chmod +x /docker-entrypoint.d/99-configure.sh

# Copy the built react application to the nginx folder
COPY ./dist /usr/share/nginx/html

Expand Down
17 changes: 17 additions & 0 deletions docker/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

if ! [ -z "$BASEPATH" ]; then
echo "Replacing basepath with: $BASEPATH"

# Escape BASEPATH for sed substitution
# - replaces / with \/
# - replaces " with \"
escaped_basepath=$(printf '%s\n' "$BASEPATH" | sed -e 's/[\/&]/\\&/g' -e 's/"/\\"/g')

# run the substitution
# replaces <base href="/" />
# with whatever BASEPATH is set to
sed -i "s/<base href=\"\/\" \/>/<base href=\"$escaped_basepath\" \/>/g" /usr/share/nginx/html/index.html

echo "Replaced basepath in index.html"
fi
5 changes: 4 additions & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
import { useHotkeys, useLocalStorage } from "@mantine/hooks";
import { Notifications } from "@mantine/notifications";
import {
createHashHistory,
ReactLocation,
Router,
createHashHistory,
} from "@tanstack/react-location";
import { ChatRoute } from "../routes/ChatRoute";
import { IndexRoute } from "../routes/IndexRoute";
Expand All @@ -31,8 +31,11 @@ export function App() {

useHotkeys([["mod+J", () => toggleColorScheme()]]);

const basepath = document.querySelector("base")?.getAttribute("href") || "/";

return (
<Router
basepath={basepath}
location={location}
routes={[
{ path: "/", element: <IndexRoute /> },
Expand Down
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
-webkit-app-region: no-drag;
}
</style>

<!-- If this line changes, update it in docker/configure.sh too -->
<base href="/" />
</head>
<body>
<div id="app"></div>
Expand Down
Loading