Welcome! Log In Create A New Profile

Advanced

How to send all these requests to the same file when I have an Angular state based router?

September 02, 2015 01:37PM
I'm using the Angular ui-router which uses states to control the routes.

Meaning that all request should serve the same index.html file, and the JavaScript worries about loading in appropriate content.

The .htaccess rules that control the same thing are below:
<ifModule mod_rewrite.c>
RewriteEngine On
# Required to allow direct-linking of pages so they can be processed by Angular
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index RewriteRule (.*) index.html [L]
</ifModule>

I'm trying to achieve the same effect, but I'm serving content through nginx. I tried to achieve this by adding the third location block in the nginx config below, however, this didn't seem to do the trick (404s). It tries to catch all routes that are not /auth.

What am I missing here?

server {
listen 80 default_server;

root /var/www/..../dist;
index index.html index.html;

# Make site accessible from http://localhost/
server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

location /auth{
proxy_pass http://auth;
}

location /^(?!auth$).* {
try_files $uri /var/www/..../dist/index.html;
}
}
Subject Author Posted

How to send all these requests to the same file when I have an Angular state based router?

maplesyrupandrew September 02, 2015 01:37PM

Re: How to send all these requests to the same file when I have an Angular state based router?

Francis Daly September 02, 2015 03:06PM

Re: How to send all these requests to the same file when I have an Angular state based router?

maplesyrupandrew September 07, 2015 08:16PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 102
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready