-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
fix: allow app to run in a subfolder via BASE_URL #461
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi!
Thank you for the PR and tackling those issues 🙏🏻
Just a small request:
- Please import the
config
fromscr/config.ts
and useconfig.app.baseUrl
This reverts commit 73c867e.
I tried importing Because |
Yeah you're right, I did not thought of this 🤔 Thank you for this PR 🙏🏻 |
Kudos, SonarCloud Quality Gate passed!
|
Hi @CorentinTh , @rmtsrc , Can you confirm if the "BASE_URL" env variable can be used while deploying the docker image? |
I believe that It is possible to build your own Docker image with a custom # Add this before "RUN pnpm build"
ARG BASE_URL
ENV BASE_URL=${BASE_URL} Then rebuild and run the container via: docker build -t it-tools --build-arg BASE_URL="/my-folder/" .
docker run -d --name it-tools --restart unless-stopped -p 8080:80 it-tools Then if you go to So you would need to put another server in front of it, like Nginx Proxy Manager, Traefik, caddy etc. Then setup a reverse proxy pass using |
Hi @rmtsrc , Thanks for the feedback, and the detailed instructions. Based on @CorentinTh I got the feeling that the env variable was not expected to work on runtime. @CorentinTh , do you have any plans to implement this feature (BASE_URL on runtime) in the future? Thanks in advance, |
Hello, Hopefully we get this feature (BASE_URL on runtime) in future. $ cat build.sh
#!/usr/bin/env bash
TMP_DIR=$(mktemp -d -t "${1}.XXXXXXX")
LATEST_TAG=$(curl -sS https://api.github.com/repos/CorentinTh/it-tools/releases/latest | jq -r '.tag_name')
pushd ${TMP_DIR} 1>/dev/null
echo "[*] Download ${TMP_DIR}/${LATEST_TAG}.tar.gz"
curl -sSOL "https://github.com/CorentinTh/it-tools/archive/refs/tags/${LATEST_TAG}.tar.gz"
DIR_NAME=$(tar -tf ${LATEST_TAG}.tar.gz | head -1)
echo "[*] Extract ${LATEST_TAG}.tar.gz"
tar -xf ${LATEST_TAG}.tar.gz
pushd $DIR_NAME 1>/dev/null
echo "[*] Update BASE_URL in Dockerfile"
# Update your BASE_URL below!
sed -i '/RUN pnpm build/i ENV BASE_URL="/it-tools/"' Dockerfile
echo "[*] Run docker build"
docker build -t it-tools .
echo "[*] Remove ${TMP_DIR}"
rm -rf ${TMP_DIR}
|
great genius! #461 (comment) |
Don't you need to add the I had problems before I added the env variable to the second stage also. |
Closes #356 #423
Some services such as GitHub pages will host the app in a subfolder such as
https://<username>.github.io/<repo-name>/
Currently when trying to self host it-tools via a GitHub pages action the
BASE_URL
environment variable was ignored and theindex.html
file was requesting JavaScript and CSS from/assets/...
, rather than/<subfolder>/assets/...
This PR allows the
BASE_URL
to be used to correctly set the full URL of the app allowing both/
and/<subfolder>/
To build using a custom folder:
BASE_URL="/it-tools/" pnpm build
dist
folder toit-tools
and serve onhttps://your-domain.com/it-tools
To build for GitHub Pages:
.github/workflows/deploy-pages.yaml