fix: nginx setup
This commit is contained in:
1 parent
400e0408f3
commit
40b6afd85c
5 files changed
+31
-11
No files matched your search
+9
-2
@@ -1,10 +1,17 @@
|
||||
# Pfad, unter dem die App ausgeliefert wird, z.B. /ue1
|
||||
ARG BASE_PATH=/
|
||||
|
||||
FROM node:26-trixie-slim AS build
|
||||
ARG BASE_PATH
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
RUN BASE_PATH="$BASE_PATH" npm run build
|
||||
|
||||
FROM nginx:mainline-trixie
|
||||
ARG BASE_PATH
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
# Willkommensseite des Images entfernen
|
||||
RUN rm -rf /usr/share/nginx/html/*
|
||||
COPY --from=build /app/dist /usr/share/nginx/html/${BASE_PATH}
|
||||
+5
-2
@@ -4,6 +4,9 @@ server {
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
|
||||
# Weiterleitung von /ue1 auf /ue1/ relativ, damit sie hinter einem Reverse Proxy stimmt
|
||||
absolute_redirect off;
|
||||
|
||||
gzip on;
|
||||
gzip_types text/css application/javascript image/svg+xml;
|
||||
|
||||
@@ -12,8 +15,8 @@ server {
|
||||
add_header Cache-Control "no-cache";
|
||||
}
|
||||
|
||||
# Dateinamen in /assets enthalten einen Hash und ändern sich mit jedem Build
|
||||
location /assets/ {
|
||||
# Dateinamen in assets/ enthalten einen Hash und ändern sich mit jedem Build
|
||||
location ~ /assets/ {
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -1,8 +1,12 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { defineConfig, loadEnv } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
|
||||
export default defineConfig({
|
||||
// Relative Pfade, damit die App auch unter einem Unterpfad wie /ue1 läuft
|
||||
base: "./",
|
||||
plugins: [react()],
|
||||
export default defineConfig(({ mode }) => {
|
||||
// Pfad, unter dem die App ausgeliefert wird, z.B. BASE_PATH=/ue1 → https://sim.teier.net/ue1
|
||||
// Absolut statt relativ, damit die Assets auch ohne abschließenden Schrägstrich gefunden werden
|
||||
const pfad = (loadEnv(mode, ".", "").BASE_PATH ?? "").replace(/^\/+|\/+$/g, "");
|
||||
return {
|
||||
base: pfad ? `/${pfad}/` : "/",
|
||||
plugins: [react()],
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user