Search code examples
herokuember.jsember-cli

How to use ember-cli with custom server and deploy it to Heroku?


I'm thinking about rewriting my Ember app using ember cli. The main issue is that I've got a simple custom server (https://github.com/cowbell/sharedrop/blob/master/app/server.js) and I'm not sure what's the best way to handle it.

Should I use http-mocks to setup the server (e.g. enable trusted proxies or add Persona authentication middleware etc.) and all routes? The name "http-mocks" suggests that it's something that should be rather used only in development, not as a real API server.

Maybe I can simply use the server I already got and deploy it together with production version of my app generated by ember build?

What's the best way to deploy such apps to Heroku? In the first case it would probably be enough to push the whole repo and run ember server. However, what's the best way to deploy it in the second case? I guess I'd only need to push contents of generated dist folder together with server.js file and then run node server.js.


Solution

  • ember-cli exists only as a development harness, once you are ready to deploy it builds you a set of static assets any app server can host. Additionally you can take those assets put them on a CDN and take the index.html and host it from your app server.

    ember build --env production
    

    produces static assets your app server can host.

    dist/index.html // <- this should live at the root url of your app
    dist/assets/*   // <- all your assets finger printed, these can live alongside your index.html or on a CDN (the host is configurable)
    

    The http-mocks exist to fake out parts of your backend that do not yet exist.

    The proxy is meant to allow you to connect to a backend during development without needing CORs.

    All this exists to de-couple your front-end from your backend as both really have different life-cycles and an excellent interface that exists between. (HTTP)