'Deploying a SpringBoot - Angular application to digitalocean
I have a website running on my local machine and I want to deploy this application to DigitalOcean. I created a droplet, installed necessary things. My angular application starts when I enter server's ip adress:
Also I can run my spring boot app on tomcat. But these two don't run synchronously. When I run spring app on the local machine, remote angular app connnect it and work well. But I want to run it with remote spring application.
@RequestMapping("/token")
public Map<String,String> token (HttpSession session, HttpServletRequest request){
System.out.println(request.getRemoteHost());
String remoteHost= request.getRemoteHost();
int portNumber = request.getRemotePort();
System.out.println(remoteHost+":"+portNumber);
System.out.println(request.getRemoteAddr());
return Collections.singletonMap("token",session.getId());
}
This is requestmapping for login.
@Injectable()
export class LoginService {
constructor(private http: Http) { }
sendCredential(username: string, password: string) {
let url = "http://localhost:8181/token";
let encodedCredentials = btoa(username+":"+password);
let basicHeader = "Basic "+encodedCredentials;
let headers = new Headers ({
'Content-Type' : 'application/x-www-form-urlencoded',
'Authorization' : basicHeader
});
return this.http.get(url, {headers: headers});
}
And this is the function for login in angular app.
Should I change http://localhost:8181/token to something like http://138.68.76.62:8181/token ?
Solution 1:[1]
Just change it to /
@Injectable()
export class LoginService {
constructor(private http: Http) { }
sendCredential(username: string, password: string) {
let url = "/token";
let encodedCredentials = btoa(username+":"+password);
let basicHeader = "Basic "+encodedCredentials;
let headers = new Headers ({
'Content-Type' : 'application/x-www-form-urlencoded',
'Authorization' : basicHeader
});
return this.http.get(url, {headers: headers});
}
Solution 2:[2]
Use relative path and "/"
Example :
Absolute path:
let url = "http://localhost:8181/token";
Relative path:
let url = "/token";
Solution 3:[3]
If I understand you well they cant run simultaneously. Had the same problem if that is your problem and I realised the problem was with how I started Springboot in the server. If you run it from the target folder with java -jar and the name of your. I know this is late but may help some one
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Radouane ROUFID |
| Solution 2 | Vikram R |
| Solution 3 | beri |
