Skip to content

Commit 7dd8e3e

Browse files
authored
feat: allow custom base path (#78)
* bump canius lite Signed-off-by: Olivier Vernin <olivier@vernin.me> * feat: allow relative path Signed-off-by: Olivier Vernin <olivier@vernin.me> --------- Signed-off-by: Olivier Vernin <olivier@vernin.me>
1 parent 2d390f3 commit 7dd8e3e

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# build stage
2-
FROM node:lts-alpine as build-stage
2+
FROM node:lts-alpine AS build-stage
33
WORKDIR /app
44
COPY package*.json ./
55
RUN npm install
@@ -13,12 +13,16 @@ COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
1313
COPY docker/config.js /usr/share/nginx/html/config.js
1414
COPY docker/config.json /usr/share/nginx/html/config.json
1515

16+
# Copy and set up the entrypoint script
17+
COPY docker-entrypoint.sh /docker-entrypoint.sh
18+
RUN chmod +x /docker-entrypoint.sh
19+
1620
# Dynamic labels are defined from the goreleaser configuration ".goreleaser.yaml"
1721
LABEL org.opencontainers.image.authors="Olivier Vernin<me@olblak.com>"
1822
LABEL org.opencontainers.image.title="Udash-front"
1923
LABEL org.opencontainers.image.description="The Udash Frontend"
20-
LABEL org.opencontainers.image.source https://github.com/updatecli/udash-front
21-
24+
LABEL org.opencontainers.image.source=https://github.com/updatecli/udash-front
2225

2326
EXPOSE 80
27+
ENTRYPOINT ["/docker-entrypoint.sh"]
2428
CMD ["nginx", "-g", "daemon off;"]

docker-entrypoint.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to dynamically configure the application at container startup.
4+
#
5+
6+
# Set a default value for VUE_APP_BASE_URL if it's not provided
7+
export VUE_APP_BASE_URL=${VUE_APP_BASE_URL:-/}
8+
9+
echo "Setting base URL to: ${VUE_APP_BASE_URL}"
10+
11+
# Replace the placeholder in index.html
12+
# Note: Using a different delimiter for sed (#) to avoid issues with URL slashes
13+
sed -i "s#%VUE_APP_BASE_URL%#${VUE_APP_BASE_URL}#g" /usr/share/nginx/html/index.html
14+
15+
# Execute the original command passed to the entrypoint, which is "nginx -g daemon off;"
16+
exec "$@"

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
88
<title><%= htmlWebpackPlugin.options.title %></title>
9+
<base href="%VUE_APP_BASE_URL%">
910
<!-- docker configurable variables -->
1011
<script src="<%= BASE_URL %>config.js"></script>
1112
</head>

src/router/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ if (isAuthEnabled) {
131131
}
132132

133133
const router = createRouter({
134-
history: createWebHistory(process.env.BASE_URL),
134+
history: createWebHistory(),
135135
routes
136136
})
137137

vue.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module.exports = defineConfig({
1515
},
1616
},
1717

18+
// make this app "location agnostic"
19+
publicPath: './',
20+
1821
pluginOptions: {
1922
vuetify: {
2023
// https://github.com/vuetifyjs/vuetify-loader/tree/next/packages/vuetify-loader

0 commit comments

Comments
 (0)