jeudi 21 mars 2019

How do I properly forward paths to an Ember app in Nginx?

Ember cannot simply be configured like this:

location / {
    index index.html;
}

We need any possible contents of the public directory accessible from the root. E.g. my.example.com/img/logo.png

location / {
    try_files $uri $uri/ /index.html;
}

However, we need every route (path) to be a possible entry-point to the Ember app, so we need to redirect non-asset files to index.html.

I had assumed it would be something like this. This is wrong:

location / {
    try_files $uri $uri/ index.html$uri$is_args$args;
}

The routes appended to index.html result in 404.

Next attempt, use the # hash internally, don't let the user know. This is wrong:

location / {
    try_files $uri $uri/ index.html#$uri$is_args$args;
}

This does not work because # turns the rest into a comment. As far as I understand, nginx ignores # internally anyway.

Next attempt, we use ? in stead. This works:

location / {
    try_files $uri $uri/ /index.html?/$request_uri;
}

We can now 'enter' the application from any non-index path. However, now we've "used up" the query string. We can no longer use the query string, at least not as an entry path, e.g. sharable link. Hence the question:

How do I properly forward paths to an Ember app in Nginx?

  • Allow deep paths
  • Allow query string

E.g.: my.example.com/posts/pinned?sort=asc




Aucun commentaire:

Enregistrer un commentaire