Serving ember-cli App index.html From Backend Server - Breaks Ember Routes


#1

In the ‘Lightning Fast’ deployment approach (on YouTube), it is recommended to serve the Ember app’s index.html file from the backend server. I think this is a great idea, as it reduces CORS complexity and gives access to the backend routes to the Ember app.

What I’m having trouble resolving rightnow is that doing it this way seems to break the routing in Ember. For example, if the Ember app has a route at /about, visiting /about will not work. The backend and frontend have entirely separate routes.

This seems to be a popular and sensible approach, so I feel like I’m missing a vital piece of information.


#2

If your on Apache add this to your public folder:

https://github.com/broerse/ember-cli-blog/blob/master/public/.htaccess


#3

How does this work? You can rewrite the URL to whatever you want, but the backend knows nothing about the Ember routes. I was under the impression that the Ember files are static Javascript and can thus be served from a backend and be stored separately, e.g. on S3.


#4

You have to tell your backend to serve the same index.html for each route but leave folders like assets/* alone. So

You will also need rewrite rules for S3. See: https://github.com/Kerry350/ember-deploy-s3-index#using-history-location


#5

I see. Now that makes sense.

This seems like a very important fact of deployment that I haven’t come across anywhere else.


#6

For example, the example Sinatra server in the ember-cli-deploy documentation looks like this:

require 'sinatra'
require 'redis'

get '/' do
  content_type 'text/html'

  redis = Redis.new
  index_key = redis.get("<your-project-name>:current")
  index_key = "<your-project-name>:#{params[:index_key]}" if params[:index_key]
  redis.get(index_key)
end

This says that only the / route serves the index.html file. I just don’t see how that could work.


#7

Nice it makes sense now. I never looked at Sinatra so I hope someone can help you with that. The concept is still the same.