fix: allow app to run in a subfolder via BASE_URL#461
fix: allow app to run in a subfolder via BASE_URL#461CorentinTh merged 5 commits intoCorentinTh:mainfrom rmtsrc:allow-subfolders
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
CorentinTh
left a comment
There was a problem hiding this comment.
Hi!
Thank you for the PR and tackling those issues 🙏🏻
Just a small request:
- Please import the
configfromscr/config.tsand 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-toolsThen 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. |
|
Hi @rmtsrc , @Majramos , @YealKio , @veerendra2 , @kurotorakun , implemented BASE_URL (and config sample) in my fork, if you arr interested in up to date version of it-tools, I made kind of a fork here : https://github.com/sharevb/it-tools (https://sharevb-it-tools.vercel.app/ and docker images https://github.com/sharevb/it-tools/pkgs/container/it-tools) Detailed explaination: https://github.com/sharevb/it-tools?tab=readme-ov-file#docker-compose-for-hosting-in-a-it-tools-subfolder and https://github.com/sharevb/it-tools?tab=readme-ov-file#docker-compose-for-hosting-in-a-it-tools-subfolder |








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_URLenvironment variable was ignored and theindex.htmlfile was requesting JavaScript and CSS from/assets/..., rather than/<subfolder>/assets/...This PR allows the
BASE_URLto 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 builddistfolder toit-toolsand serve onhttps://your-domain.com/it-toolsTo build for GitHub Pages:
.github/workflows/deploy-pages.yaml