Skip to content

Commit

Permalink
🐛(frontend) fix Nginx configuration for SPA routing with Vite
Browse files Browse the repository at this point in the history
Configured Nginx to serve index.html for all requests, allowing
the client-side router (Wouter) to manage the routing.

Added a try_files directive to attempt to serve static files first,
falling back to index.html if the requested file is not found.

Added an error_page directive to handle 404 errors by internally
redirecting to index.html without modifying the URL path.

Wouter should make the rest.
  • Loading branch information
lebaudantoine committed Jul 15, 2024
1 parent 6e3bf3b commit eac107a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/frontend/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ server {

root /usr/share/nginx/html;

# Serve static files
location / {
try_files $uri index.html $uri/ =404;
try_files $uri $uri/ /index.html;
# Add no-cache headers
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache"; # HTTP 1.0 header for backward compatibility
add_header Expires 0;
}

error_page 404 /404.html;
location = /404.html {
internal;
}
# Optionally, handle 404 errors by redirecting to index.html
error_page 404 =200 /index.html;

}

0 comments on commit eac107a

Please sign in to comment.