How to build Angular 4 applications in Nginx or Apache HTTPD?

Hi, I am trying to build an Angular 4 application, the next steps are as follows –

Build build

In my In the amazon ec2 instance, I am running apache. The steps followed –

#!/bin/bash
yum install httpd -y
yum update -y
cp dist/* /var/www/html/
service httpd start
chkconfig httpd on

Everything is ok, but my application uses auth0 for identity Verification, I see that they call back to http: // ip/callback

My application form-404 not found.

app-problem

I tried to build something like ng build –base-href. It didn’t work!
Please help me how to build this, please note that when I use the service locally, everything is great. But when I try to deploy to production, it gives this error. I am pretty sure when building the app What I am doing.

I tried the nginx docker container and it gave the same error. My docker file looks like this.

From nginx
COPY dist /usr/share / nginx / html

> docker build -t ng-auth0-web-dev.
> docker run -d -p 8080: 80 ng-auth0-web-dev< /p>

Is there anything wrong with the docker file above?

https://github.com/auth0-samples/auth0-angular-samples/tree/master/01-Login – sample application code

07002 – No error in logs, that means auth0 is working fine but I am getting build error with angular.

Exact error:

enter image description here

auth0 callback settings

Update –

I also tried a building like this –
ng build –base-href http ://34.213.164.54/
and ng build –base-href http://34.213.164.54:80/, but the same error.

So the question is how to narrow it down to how I build Angular App

public handleAuthentication(): void {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult. accessToken && authResult.idToken) {
window.location.hash ='';
this.setSession(authResult);
localStorage.setItem('email', profile.email);
this.verticofactoryService.registerUser(u);
this.router.navigate(['/home']);
});



} else if (err) {
this.router.navigate(['/home']);
console.log(err);
alert(`Error: ${err.error }. Check the console for further details.`);
}
});
}

Angular applications are ideal for serving a simple static HTML server. You don’t need a server-side engine to dynamically compose application pages because Angular does this on the client side.

If the application uses the Angular router, the server must be configured to return the application’s host page (index.html) when it is asked to provide a file that it does not have.

Suppose you The nginx server conf just add something like this. try_files $uri $uri / /index.html;

Reference – https://github.com/auth0-samples/auth0-angular-samples/tree/ master/02-User-Profile

Thank you JB Nizet, it finally worked.

server conf

Hi, I am trying to build an Angular 4 application, the next steps are as follows-

< p>Build build

In my amazon ec2 instance, I am running apache. The steps followed –

#!/bin/bash
yum install httpd -y
yum update -y
cp dist/* /var/www/html/
service httpd start
chkconfig httpd on

Everything is ok, but my application uses auth0 for authentication, and I see that they call back to http://ip/callback

My application form-404 not found.

app-problem

I tried to build something like ng build –base-href. It didn’t work!
Please help me how to build this, please note that when I use the service locally, everything is great. But when I try to deploy to production, it gives this error. I am pretty sure when building the app What I am doing.

I tried the nginx docker container and it gave the same error. My docker file looks like this.

From nginx
COPY dist /usr/share / nginx / html

> docker build -t ng-auth0-web-dev.
> docker run -d -p 8080: 80 ng-auth0-web-dev< /p>

Is there anything wrong with the docker file above?

https://github.com/auth0-samples/auth0-angular-samples/tree/master/01-Login – sample application code

07002 – No error in logs, that means auth0 is working fine but I am getting build error with angular.

Exact error:

enter image description here

auth0 callback settings

Update –

I also tried a building like this –
ng build –base-href http ://34.213.164.54/
and ng build –base-href http://34.213.164.54:80/, but the same error.

So the question is how to narrow it down to how I build Angular App

public handleAuthentication(): void {
this.auth0.parseHash((err, authResult) => {
if (authResult && authResult. accessToken && authResult.idToken) {
window.location.hash ='';
this.setSession(authResult);
localStorage.setItem('email', profile.email);
this .verticofactoryService.registerUser(u);
this.router.navigate(['/home']);
});



} else if (err) {
this.router.navigate(['/home']);
console.log(err);
alert(`Error: ${err.error} . Check the console for further details.`);
}
});
}

Angular application is Ideal for serving a simple static HTML server. You don’t need a server-side engine to dynamically compose application pages because Angular does this on the client side.

If the application uses Angular routers , The server must be configured to return the application’s host page (index.html) when it is asked to provide a file that it does not have.

Assuming that your nginx server conf just adds something like this. try_files $uri $uri / /index.html;

Reference-https://github.com/auth0-samples/auth0-angular-samples/tree/master/02-User-Profile

Thank you JB Nizet, it finally worked.

server conf

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4673 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.