Deploy application using --Prod and path strategy

Asked

Viewed 51 times

0

I’m trying to deploy angular application 8

When I use the command

ng build --prod --base-href /app/

When I try to run the application on localhost/app

The app does not load

On the console you have this message:

http://localhost/app/main-es2015.de53c17ebee928a1e2c9.js net::ERR_ABORTED 404 (Not Found)

But when I deploy it without the --prod it runs the application, however, if I refresh the page, the server cannot find the page

I can only update the page if I deploy using the Hash strategy

providers: [
    //{provide: LocationStrategy, useClass: HashLocationStrategy} //adicionar um # a url
  ]

[Edit]

I’m using Apache server 2.4

My file . htaccess inside the app folder (localhost/app) looks like this:

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

As documented

  • which server you are using?

  • I used Apache server 2.4

  • https://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml take a look at this configuration of your htaccess, at least it will make sure that when you update it doesn’t lose the page

  • That’s where I got the configuration

  • tries Rewriterule /app/index.html

  • It worked, buddy! That’s right. . htacess, now missing the --Prod

  • Gave this here: Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec. when I used the --prod

  • Try to see if this file that he is looking for actually exists on the server and the path is correct

  • When I deploy without --prod the application runs normal... To provide the application with the production api address, I have to change the address on environment and is already configured in environment.prod

  • @Eduardovargas put your answer on the . htaccess I’m going to settle on the deploy with --prod.. You’ve helped a lot

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.