kattybilly
kattybilly

Reputation: 117

Ember Cli Deploy via Lighting Strategy

We have deployed our Ember App using Lightning Deploy Strategy which involves:

When, upon hitting the instance, the index.html gets served from Redis, and subsequently on clicking any route in the App, the App routes get served.

But, when we manually enter any correct route in URL for the Ember App, Nginx throws an error saying route not found. Anything wrong that we are doing here?

Upvotes: 1

Views: 170

Answers (2)

Ajeet Khan
Ajeet Khan

Reputation: 9190

When a subrequest, say, mydomain.com/login is hit with the url or the page is refreshed, the browser sends a requests to nginx and nginx won't be able to find the login page anywhere and will return a 404 error. This is because nginx won't be able to pass the subroutes to index.html page which in turn can serve the subroutes. To solve this the following location block is used in nginx.

  # This block handles the subrequest. If any subroutes are requested than this rewrite the url to root and tries to render the subroute page by passing the subroute to index file (which is served by the redis).
  location ~* / {
  rewrite ^ / last;
  }

Here we are saying to nginx, for any subrequests, rewrite the url to root (/) location (root location serves the index page from redis) and find the requested page. The last option tries to find the particular page by revisiting all the blocks defined in nginx as a result of which it is able to go to root location. A detailed explanation and full nginx config can be found here.

Upvotes: 3

Pedro Rio
Pedro Rio

Reputation: 1444

If I'm understanding you correctly, you need to let ember to all the routing.

What's happening is that when you hit index.html, redis serves the instance, but when you hit any other url you need to tell nginx to serve the same index.html and let ember process the route.

I've found this on the Ember Discuss which may be of help.

server {
listen 80 default;
server_name my.domain.com;
root /path/to/app/root;

location / {
    rewrite ^ /index.html break;
}

location /assets/ {
    # do nothing and let nginx handle this as usual
}
}

I'm using the Play Framework and I'm using the Lighting Deploy Strategy as well and I had to create a route /* which gets routes to my controller which in turn retrieves the index from redis.

Upvotes: 2

Related Questions