API URL was not taken from environment after docker container and npm was build
CORS prevented from loading
This commit is contained in:
@@ -26,6 +26,9 @@ type Config struct {
|
|||||||
|
|
||||||
DevTesting string // "yes" or "no", used to determine if we are in a test environment
|
DevTesting string // "yes" or "no", used to determine if we are in a test environment
|
||||||
|
|
||||||
|
// Frontend URLs for CORS
|
||||||
|
FrontendURL string // Frontend URL for CORS configuration
|
||||||
|
|
||||||
// PDF Templates
|
// PDF Templates
|
||||||
TemplatesDir string // Directory where PDF templates are stored
|
TemplatesDir string // Directory where PDF templates are stored
|
||||||
ExportTempDir string // Directory for temporary PDF exports
|
ExportTempDir string // Directory for temporary PDF exports
|
||||||
@@ -50,6 +53,7 @@ func defaultConfig() *Config {
|
|||||||
LogLevel: "INFO",
|
LogLevel: "INFO",
|
||||||
Environment: "production",
|
Environment: "production",
|
||||||
DevTesting: "no", // Default to "no", can be overridden in tests
|
DevTesting: "no", // Default to "no", can be overridden in tests
|
||||||
|
FrontendURL: "http://localhost:5173", // Default frontend URL for development
|
||||||
TemplatesDir: "./templates", // Default templates directory
|
TemplatesDir: "./templates", // Default templates directory
|
||||||
ExportTempDir: "./xporttemp", // Default export temp directory
|
ExportTempDir: "./xporttemp", // Default export temp directory
|
||||||
}
|
}
|
||||||
@@ -117,6 +121,10 @@ func LoadConfig() *Config {
|
|||||||
fmt.Printf("DEBUG LoadConfig - DEVTESTING nicht gefunden, setze DevTesting auf 'no'\n")
|
fmt.Printf("DEBUG LoadConfig - DEVTESTING nicht gefunden, setze DevTesting auf 'no'\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Frontend URL
|
||||||
|
if frontendURL := os.Getenv("BASE_URL"); frontendURL != "" {
|
||||||
|
config.FrontendURL = frontendURL
|
||||||
|
|
||||||
// Templates Directory
|
// Templates Directory
|
||||||
if templatesDir := os.Getenv("TEMPLATES_DIR"); templatesDir != "" {
|
if templatesDir := os.Getenv("TEMPLATES_DIR"); templatesDir != "" {
|
||||||
config.TemplatesDir = templatesDir
|
config.TemplatesDir = templatesDir
|
||||||
|
|||||||
+11
-1
@@ -1,18 +1,28 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bamort/config"
|
||||||
|
|
||||||
"github.com/gin-contrib/cors"
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupGin(r *gin.Engine) {
|
func SetupGin(r *gin.Engine) {
|
||||||
|
// Build allowed origins list from configuration
|
||||||
|
allowedOrigins := []string{
|
||||||
|
config.Cfg.FrontendURL,
|
||||||
|
"http://localhost:5173", // Development frontend
|
||||||
|
"https://bamort.trokan.de", // Production frontend
|
||||||
|
}
|
||||||
|
|
||||||
// Add CORS middleware
|
// Add CORS middleware
|
||||||
r.Use(cors.New(cors.Config{
|
r.Use(cors.New(cors.Config{
|
||||||
//AllowOrigins: []string{"http://localhost:3000"}, // Replace with your frontend's URL
|
//AllowOrigins: []string{"http://localhost:3000"}, // Replace with your frontend's URL
|
||||||
AllowOrigins: []string{"*"},
|
AllowOrigins: allowedOrigins,
|
||||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||||
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
|
||||||
ExposeHeaders: []string{"Content-Length"},
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
|
MaxAge: 12 * 3600, // Cache preflight for 12 hours
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
# =========== 1) Build stage ===========
|
# =========== 1) Build stage ===========
|
||||||
FROM node:22-alpine AS build
|
FROM node:22-alpine AS build
|
||||||
|
|
||||||
|
# Accept build arguments for Vite environment variables
|
||||||
|
ARG VITE_API_URL
|
||||||
|
ARG VITE_BASE_URL
|
||||||
|
ARG VITE_API_PORT
|
||||||
|
|
||||||
|
# Set them as environment variables for the build process
|
||||||
|
ENV VITE_API_URL=$VITE_API_URL
|
||||||
|
ENV VITE_BASE_URL=$VITE_BASE_URL
|
||||||
|
ENV VITE_API_PORT=$VITE_API_PORT
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Copy package files
|
# Copy package files
|
||||||
|
|||||||
@@ -24,13 +24,17 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ../frontend
|
context: ../frontend
|
||||||
dockerfile: ../docker/Dockerfile.frontend
|
dockerfile: ../docker/Dockerfile.frontend
|
||||||
|
args:
|
||||||
|
VITE_API_URL: ${API_URL:-https://bamort.trokan.de:8180}
|
||||||
|
VITE_BASE_URL: ${BASE_URL:-https://bamort.trokan.de}
|
||||||
|
VITE_API_PORT: ${API_PORT:-8180}
|
||||||
container_name: bamort-frontend
|
container_name: bamort-frontend
|
||||||
ports:
|
ports:
|
||||||
- "8181:80"
|
- "8181:80"
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- VITE_API_URL=${API_URL:-http://bamort.trokan.de:8180}
|
- VITE_API_URL=${API_URL:-https://bamort.trokan.de:8180}
|
||||||
- VITE_BASE_URL=${BASE_URL:-http://bamort.trokan.de}
|
- VITE_BASE_URL=${BASE_URL:-https://bamort.trokan.de}
|
||||||
- VITE_API_PORT=${API_PORT:-8180}
|
- VITE_API_PORT=${API_PORT:-8180}
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "🚀 Starting Bamort Development Environment..."
|
echo "🚀 Starting Bamort Production Environment..."
|
||||||
|
|
||||||
# Prüfe ob Docker läuft
|
# Prüfe ob Docker läuft
|
||||||
if ! docker info > /dev/null 2>&1; then
|
if ! docker info > /dev/null 2>&1; then
|
||||||
@@ -11,7 +11,7 @@ fi
|
|||||||
# Gehe ins Docker-Verzeichnis
|
# Gehe ins Docker-Verzeichnis
|
||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
echo "📦 Building and starting development containers..."
|
echo "📦 Building and starting production containers..."
|
||||||
|
|
||||||
# Stoppe vorhandene Container
|
# Stoppe vorhandene Container
|
||||||
docker-compose -f docker-compose.yml down
|
docker-compose -f docker-compose.yml down
|
||||||
@@ -19,4 +19,4 @@ docker-compose -f docker-compose.yml down
|
|||||||
# Baue und starte die Container
|
# Baue und starte die Container
|
||||||
docker-compose -f docker-compose.yml up --build -d
|
docker-compose -f docker-compose.yml up --build -d
|
||||||
|
|
||||||
echo "✅ Development environment started."
|
echo "✅ Production environment started."
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
const API = axios.create({
|
const API = axios.create({
|
||||||
baseURL: import.meta.env.VITE_API_URL || 'http://localhost:8180', // Use env variable with fallback
|
baseURL: import.meta.env.VITE_API_URL || 'https://bamort.trokan.de:8180', // Use env variable with fallback
|
||||||
})
|
})
|
||||||
|
|
||||||
// Request interceptor to add auth token
|
// Request interceptor to add auth token
|
||||||
|
|||||||
Reference in New Issue
Block a user