5

I've set up a website using Ember-CLI and it is now ready for production, so we're looking for a way to keep it running permanently.

Right now we're using $ ember serve --port 80

but obviously this only works whilst we're logged in. I've used Forever before to keep a node app running but am not sure how to make this work with Ember CLI, as the 'ember serve' command obviously does more than just running app.js?

Any input would be appreciated!

James Gupta
  • 871
  • 7
  • 15

1 Answers1

7

Ember-CLI apps are NOT node apps, they are Browser apps, so you don't need anything special to serve them. To keep and Ember-CLI app running permanently, I suggest doing:

ember build --environment=production

This will perform the necessary build steps so that the code works in browsers (e.g, transpiling ES6 modules) and put the code in the build folder. It will also minify JS files and fingerprint all resources (this only happens when the environment is production).

All you have to to then is put the files inside the dist/ folder on a Web Server.

I suggest Apache or Nginx, but anything will work.

Edit

As Omair Vaiyani pointed out, this might not work in some servers because Ember-CLI uses the locationType: 'auto' which defaults to 'history'. For that to work, you have to configure your SERVER to serve the ember app from all routes.

What I do, and server me well because I don't have control over the server, is to simply change the locationType to 'hash', which will generate URLs with hashes (http://myemberapp/#/myroute/myid) and will work with any server. Just edit the environment.js file accordingly:

module.exports = function(environment) {
   var ENV = {
      /* other stuf ... */
      locationType: 'hash',
      /* other stuf ... */
   },
   /* other stuff */

```

Paulo Schreiner
  • 1,046
  • 8
  • 9
  • Ah that makes more sense, thanks! Going to try that later tonight – James Gupta Aug 10 '14 at 16:26
  • 1
    ember-cli uses express on node to handle routing before the website is loaded. So this method results in a 404 error if you try and directly access a non 'index' route. Any suggestions for this @jorjao81 – Omair Vaiyani Aug 10 '14 at 18:58
  • @OmairVaiyani I'm just using the 'hash' location type instead of 'auto'. In the ember environment.js file make change: `locationType: 'auto'` to `locationType: 'hash',` This will generate URLs with a hashmark, and will work with ANY webserver (I deploy to amazon S3) You can configure other servers to work with the default 'auto' locationType if you really want to – Paulo Schreiner Aug 11 '14 at 15:44
  • 1
    @jorjao81 I avoid using hash locations in case they cause problems with SEO. Instead, we found these apache or nginx rules that seem to be doing the trick: http://iamstef.net/ember-app-kit/guides/deployment.html – Omair Vaiyani Aug 12 '14 at 15:33
  • Wow, this question really help, thanks. Coz I'm using PHP Slim as backend and really need xampp to host it, instead of using Node as the webserver – jumper rbk Sep 08 '14 at 10:08