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

Add BASE_URL environment configuration #529

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apt update
RUN apt install -y curl htop
RUN apt install -y nginx
RUN apt install -y libdbi-perl libdbd-pg-perl
RUN apt install -y gettext

# move build files to container
COPY service/build /opt/service
Expand Down
7 changes: 7 additions & 0 deletions docker/production/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ nginx -v
export GIN_MODE=release
/opt/service/ivory &

# insert base url
envsubst '\$BASE_URL' < /etc/nginx/nginx.conf > "/etc/nginx/nginx.conf.tmp" && mv "/etc/nginx/nginx.conf.tmp" "/etc/nginx/nginx.conf"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, I don't like this solution, I was checking as well how to do it better, the main problem that nginx doesn't work with env variables, I want to check if there is more elegant way to do this. I'm even thinking changing nginx 😂

Copy link
Contributor Author

@dodo920306 dodo920306 Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I understand. It's a little bit awkward, but even Nginx themself use envsubst in their images.
Anyway, I'm also wondering if there is a better solution🤔.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and there is one more problem that even when we have relative path in html, it doesn't work properly with trailing slash, to work it correctly we need to add <base> element with this url. I'm trying to do it right now will see. I will share the changes with a bit later today probably.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't work properly with trailing slash

I don't get it, but I guess I'll see it in the changes👍.

Copy link
Contributor

@anselvo anselvo Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've decided to get rid of nginx and use go server, I wanted it to do long time ago, because it will help to ease setup of TLS and usage of http/2. You can check it here #530 I will release it under 1.3.4.

P.S. Thanks for you effort, your comments were useful, it helped me to know something new, hope you as well :)
P.S.S I will close this PR

if [ -n "${BASE_URL}" ]; then
sed -i "s/location \//location \\${BASE_URL}/g" /etc/nginx/nginx.conf
sed -i "s/api/\/api/g" /etc/nginx/nginx.conf
fi

# run nginx server
/usr/sbin/nginx &

Expand Down
3 changes: 2 additions & 1 deletion docker/production/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ http {
listen 80;

location / {
root /opt/web;
alias /opt/web/;
index index.html;
try_files $uri $uri/ =404;
}

location /api {
rewrite ${BASE_URL}(.*) $1 break;
proxy_set_header Connection '';
proxy_pass http://localhost:8080;
# we need this for events-stream we don't want to gzip or cache any data
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {AppConfig, AppInfo, Login, Response, Sidecar} from "../type/general";
import {Bloat, BloatRequest} from "../type/bloat";
import {Cluster, ClusterAuto, ClusterMap} from "../type/cluster";

export const api = axios.create({baseURL: '/api'})
export const api = axios.create({baseURL: './api'})

export const GeneralApi = {
info: {
Expand Down
Loading