Skip to content

Instantly share code, notes, and snippets.

@johngrimes
johngrimes / nginx.conf
Created February 14, 2018 22:23
Ideal Nginx configuration for JavaScript single-page app
server {
listen 80;
root /usr/share/nginx/html;
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
gzip_comp_level 9;
etag on;
location / {
try_files $uri $uri/ /index.html;
}
@srikarn
srikarn / spring-boot-angular.txt
Last active October 28, 2023 08:55
Spring boot configuration to forward to index page on 404
@Bean
ErrorViewResolver redirectToFrontEndOn404() {
return ( request, status, model ) -> status == HttpStatus.NOT_FOUND
? new ModelAndView("forward:/index.html", Collections.<String, Object>emptyMap(), HttpStatus.OK)
: null;
}
This is necessary on page refresh to avoid showing 404 or error pages
This forward also maintains the client route path, so angular will route to the correct route on reload.