mirror of
https://dev.azure.com/tstanciu94/ReverseProxy/_git/ReverseProxy_Frontend
synced 2025-10-03 16:49:04 +03:00
Enhance Dockerfile and nginx configuration for dynamic subfolder handling and improved asset caching
This commit is contained in:
parent
0bfbe6e9f2
commit
caf38d468f
10
Dockerfile
10
Dockerfile
@ -35,8 +35,14 @@ RUN if [ -n "$APP_SUBFOLDER" ]; then mkdir -p /usr/share/nginx/html/$APP_SUBFOLD
|
|||||||
# Copy built application
|
# Copy built application
|
||||||
COPY --from=builder /app/build /usr/share/nginx/html/${APP_SUBFOLDER}
|
COPY --from=builder /app/build /usr/share/nginx/html/${APP_SUBFOLDER}
|
||||||
|
|
||||||
# Copy nginx configuration
|
# Copy and configure nginx
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
COPY nginx.conf /tmp/nginx.conf.template
|
||||||
|
# Generate nginx.conf with correct subfolder path
|
||||||
|
RUN if [ -n "$APP_SUBFOLDER" ]; then \
|
||||||
|
sed "s|# SUBFOLDER_PLACEHOLDER|location /$APP_SUBFOLDER/ { try_files \$uri \$uri/ /$APP_SUBFOLDER/index.html; }|g" /tmp/nginx.conf.template > /etc/nginx/nginx.conf; \
|
||||||
|
else \
|
||||||
|
sed "s|# SUBFOLDER_PLACEHOLDER||g" /tmp/nginx.conf.template > /etc/nginx/nginx.conf; \
|
||||||
|
fi
|
||||||
|
|
||||||
# Add environment variables
|
# Add environment variables
|
||||||
ENV Author="Tudor Stanciu"
|
ENV Author="Tudor Stanciu"
|
||||||
|
10
nginx.conf
10
nginx.conf
@ -46,15 +46,17 @@ http {
|
|||||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://cdn.jsdelivr.net; font-src 'self' https://fonts.gstatic.com; connect-src 'self' http: https:;" always;
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob: https://cdn.jsdelivr.net; font-src 'self' https://fonts.gstatic.com; connect-src 'self' http: https:;" always;
|
||||||
|
|
||||||
# Static assets caching - works for any subfolder or root
|
# Static assets caching - works for any subfolder or root
|
||||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|json)$ {
|
||||||
expires 1y;
|
expires 1y;
|
||||||
add_header Cache-Control "public, immutable";
|
add_header Cache-Control "public, immutable";
|
||||||
|
try_files $uri =404;
|
||||||
}
|
}
|
||||||
|
|
||||||
# SPA fallback - handle client-side routing for React apps
|
# Dynamic subfolder configuration (generated at build time)
|
||||||
|
# SUBFOLDER_PLACEHOLDER
|
||||||
|
|
||||||
|
# SPA fallback for root level routes
|
||||||
location / {
|
location / {
|
||||||
# First try to serve request as file, then as directory
|
|
||||||
# If both fail, serve index.html for SPA routing
|
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user