Fix connections between pods
This commit is contained in:
parent
e0dec56b1d
commit
7cadc006d3
1
frontend/.env
Normal file
1
frontend/.env
Normal file
@ -0,0 +1 @@
|
|||||||
|
VITE_API_URL=http://localhost:8000
|
||||||
@ -1,26 +1,20 @@
|
|||||||
# Stage 1: Build
|
# Stage 1: Build
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install --legacy-peer-deps
|
RUN npm install --legacy-peer-deps
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Serve with nginx
|
# Stage 2: NGINX
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
|
|
||||||
# Remove default nginx static files
|
|
||||||
RUN rm -rf /usr/share/nginx/html/*
|
RUN rm -rf /usr/share/nginx/html/*
|
||||||
|
|
||||||
# Copy built assets from the builder stage
|
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy custom nginx config if needed
|
# Runtime env injection
|
||||||
# COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
RUN chmod +x /docker-entrypoint.sh
|
||||||
|
RUN echo "window.env = {}" > /usr/share/nginx/html/env.js
|
||||||
|
|
||||||
EXPOSE 80
|
CMD ["/docker-entrypoint.sh"]
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
|
|||||||
11
frontend/docker-entrypoint.sh
Normal file
11
frontend/docker-entrypoint.sh
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Generate env.js at runtime
|
||||||
|
cat <<EOF > /usr/share/nginx/html/env.js
|
||||||
|
window.env = {
|
||||||
|
VITE_API_URL: "${VITE_API_URL}"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
exec nginx -g "daemon off;"
|
||||||
@ -1,11 +1,13 @@
|
|||||||
|
const API_BASE = window?.env?.VITE_API_URL || '';
|
||||||
|
|
||||||
export async function fetchSections() {
|
export async function fetchSections() {
|
||||||
const res = await fetch('/apps');
|
const res = await fetch(`${API_BASE}/apps`);
|
||||||
if (!res.ok) throw new Error('Failed to fetch sections');
|
if (!res.ok) throw new Error('Failed to fetch sections');
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addAppToSection({ section, app }) {
|
export async function addAppToSection({ section, app }) {
|
||||||
const res = await fetch('/add_app', {
|
const res = await fetch(`${API_BASE}/add_app`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ section, app })
|
body: JSON.stringify({ section, app })
|
||||||
@ -15,8 +17,8 @@ export async function addAppToSection({ section, app }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getIconUrl(filename) {
|
export async function getIconUrl(filename) {
|
||||||
const res = await fetch(`/icon/${filename}`);
|
const res = await fetch(`${API_BASE}/icon/${filename}`);
|
||||||
if (!res.ok) throw new Error(`Failed to fetch icon for ${filename}`);
|
if (!res.ok) throw new Error(`Failed to fetch icon for ${filename}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
return data.url; // ✅ must return the actual URL string
|
return data.url;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,6 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
server: {
|
|
||||||
proxy: {
|
|
||||||
'/apps': 'http://localhost:8000',
|
|
||||||
'/add_app': 'http://localhost:8000',
|
|
||||||
'/icon': 'http://localhost:8000',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -18,3 +18,6 @@ spec:
|
|||||||
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
|
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 80
|
- containerPort: 80
|
||||||
|
env:
|
||||||
|
- name: VITE_API_URL
|
||||||
|
value: "http://navix-backend.{{ .Release.Namespace }}.svc.cluster.local:8000"
|
||||||
|
|||||||
@ -10,14 +10,18 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
ingressClassName: {{ .Values.frontend.ingress.className }}
|
ingressClassName: {{ .Values.frontend.ingress.className }}
|
||||||
rules:
|
rules:
|
||||||
- host: {{ .Values.frontend.ingress.hosts[0].host }}
|
{{- range .Values.frontend.ingress.hosts }}
|
||||||
|
- host: {{ .host }}
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
- path: {{ .Values.frontend.ingress.hosts[0].paths[0].path }}
|
{{- range .paths }}
|
||||||
pathType: {{ .Values.frontend.ingress.hosts[0].paths[0].pathType }}
|
- path: {{ .path }}
|
||||||
|
pathType: {{ .pathType }}
|
||||||
backend:
|
backend:
|
||||||
service:
|
service:
|
||||||
name: navix-frontend
|
name: navix-frontend
|
||||||
port:
|
port:
|
||||||
number: {{ .Values.frontend.service.port }}
|
number: {{ $.Values.frontend.service.port }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
Loading…
x
Reference in New Issue
Block a user