3

I have developed a web application with EmberJS and I want to deploy in a real server.

When I test in localhost with environment development and command ember severything is OK, but when I create the distribution package with ember build --environment=production and deploy it using a webserver (in my case python -m SimpleHTTPServer 4200 and also with a Apache server) I get the following error when I try to access directly to a route.

Error response

Error code 404.

Message: File not found.

Error code explanation: 404 = Nothing matches the given URI.

If I enter in myaddress:4200 and navigate through links, nothing is wrong but if I want to refresh the web or change the url, the error 404 happened.

Severin Pappadeux
  • 18,636
  • 3
  • 38
  • 64
EnriMR
  • 3,924
  • 5
  • 39
  • 59
  • I m unsure how it is done with python but you will need to redirect all requests to your index.html file and only allow requests through if the file exists. – Patsy Issa Aug 24 '16 at 09:23
  • @Kitler how can I do that? What do you use to create your deploy server? – EnriMR Aug 24 '16 at 09:41
  • 4
    Possible duplicate of [Python SimpleHTTPServer](http://stackoverflow.com/questions/15401815/python-simplehttpserver) – Patsy Issa Aug 24 '16 at 09:42
  • It is not a duplicate of the question you say because I have tried to deploy it in a Apache server and the error is the same. Route does not exist – EnriMR Aug 24 '16 at 11:20
  • You asked about python's `SimpleHTTPServer`, the question is a duplicate of that question, and if you want apache then the question is a dupe of [this one](https://stackoverflow.com/questions/14845048/client-side-javascript-app-url-routing-with-no-hash-tag) – Patsy Issa Aug 24 '16 at 11:22
  • The answer to your problem is you need to configure your server be it apache/nginx or a potato to redirect all requests to index.html except for valid files such as images, css, js, etc.. – Patsy Issa Aug 24 '16 at 11:24
  • 1
    Possible duplicate of [Ember/Ember-Cli Serving through Apache throws 404](http://stackoverflow.com/questions/29535283/ember-ember-cli-serving-through-apache-throws-404) – Serabe Sep 09 '16 at 15:51

1 Answers1

0

After check the question Python SimpleHTTPServer and one issue in ember repository, the solution that I have implemented is perform deploy through Apache server and creating a .htaccess file that redirect the traffic to index.html

Options FollowSymLinks

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>
Community
  • 1
  • 1
EnriMR
  • 3,924
  • 5
  • 39
  • 59