Amend CORS
This commit is contained in:
@@ -18,13 +18,13 @@ RUN mkdir -p /runtime-config && \
|
|||||||
USER nginx
|
USER nginx
|
||||||
|
|
||||||
# Copy built assets
|
# Copy built assets
|
||||||
COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html
|
COPY --chown=nginx:nginx dist /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy our custom nginx config
|
# Copy nginx config template
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY --chown=nginx:nginx nginx.conf.template /etc/nginx/templates/
|
||||||
|
|
||||||
# Copy entrypoint script
|
# Copy entrypoint script
|
||||||
COPY docker/entrypoint.sh /entrypoint.sh
|
COPY --chown=nginx:nginx docker/entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
# Make entrypoint executable
|
# Make entrypoint executable
|
||||||
USER root
|
USER root
|
||||||
|
|||||||
@@ -4,10 +4,16 @@ set -e
|
|||||||
# Create runtime config file in writable location
|
# Create runtime config file in writable location
|
||||||
cat > /runtime-config/config.js <<EOF
|
cat > /runtime-config/config.js <<EOF
|
||||||
window.__APP_CONFIG__ = {
|
window.__APP_CONFIG__ = {
|
||||||
API_BASE_URL: "${API_BASE_URL}",
|
API_BASE_URL: "${API_BASE_URL}"
|
||||||
OTHER_VAR: "${OTHER_VAR}"
|
|
||||||
};
|
};
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Generate nginx config from template (if using)
|
||||||
|
if [ -f "/etc/nginx/templates/nginx.conf.template" ]; then
|
||||||
|
envsubst '${API_BASE_URL}' \
|
||||||
|
< /etc/nginx/templates/nginx.conf.template \
|
||||||
|
> /etc/nginx/nginx.conf
|
||||||
|
fi
|
||||||
|
|
||||||
# Start Nginx
|
# Start Nginx
|
||||||
exec nginx -g "daemon off;"
|
exec nginx -g "daemon off;"
|
||||||
@@ -18,16 +18,33 @@ http {
|
|||||||
fastcgi_temp_path /tmp/fastcgi_temp;
|
fastcgi_temp_path /tmp/fastcgi_temp;
|
||||||
uwsgi_temp_path /tmp/uwsgi_temp;
|
uwsgi_temp_path /tmp/uwsgi_temp;
|
||||||
scgi_temp_path /tmp/scgi_temp;
|
scgi_temp_path /tmp/scgi_temp;
|
||||||
|
absolute_redirect off;
|
||||||
|
|
||||||
|
map $http_origin $cors_origin {
|
||||||
|
default "";
|
||||||
|
"~*" $http_origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
upstream backend {
|
||||||
|
server localhost:8080;
|
||||||
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 8080;
|
listen 7070;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
# Handle client-side routing
|
# Handle client-side routing
|
||||||
location / {
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
|
|
||||||
|
# Security headers
|
||||||
|
add_header X-Content-Type-Options nosniff;
|
||||||
|
add_header X-Frame-Options "DENY";
|
||||||
|
add_header Referrer-Policy "strict-origin-when-cross-origin";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Serve config.js from the writable location
|
# Serve config.js from the writable location
|
||||||
@@ -37,6 +54,24 @@ http {
|
|||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/ {
|
||||||
|
# Proxy to Quarkus
|
||||||
|
proxy_pass http://backend/;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
||||||
|
# Relay CORS headers from the backend
|
||||||
|
proxy_pass_header Access-Control-Allow-Origin;
|
||||||
|
proxy_pass_header Access-Control-Allow-Methods;
|
||||||
|
proxy_pass_header Access-Control-Allow-Headers;
|
||||||
|
proxy_pass_header Access-Control-Allow-Credentials;
|
||||||
|
}
|
||||||
|
|
||||||
# Cache static assets
|
# Cache static assets
|
||||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
||||||
expires 1y;
|
expires 1y;
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {userManager} from "../stores/auth.ts";
|
import {userManager} from "../stores/auth.ts";
|
||||||
|
import {getConfig} from "@/util/config.ts";
|
||||||
|
|
||||||
const axiosInstance = axios.create()
|
const axiosInstance = axios.create({
|
||||||
|
baseURL: getConfig().API_BASE_URL || '/api',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
axiosInstance.interceptors.request.use(async (config) => {
|
axiosInstance.interceptors.request.use(async (config) => {
|
||||||
const user = await userManager.getUser()
|
const user = await userManager.getUser()
|
||||||
|
|||||||
@@ -24,16 +24,6 @@ export default defineConfig({
|
|||||||
'@': path.resolve(__dirname, './src'),
|
'@': path.resolve(__dirname, './src'),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
server: {
|
|
||||||
proxy: {
|
|
||||||
'/api': {
|
|
||||||
target: 'http://dex-be:8080',
|
|
||||||
changeOrigin: true,
|
|
||||||
secure: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
build: {
|
build: {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
assetsInclude: [
|
assetsInclude: [
|
||||||
|
|||||||
Reference in New Issue
Block a user