我在本地计算机上运行了一个网站,我想将此应用程序部署到DigitalOcean。我创建了一个Droplet,安装了必要的东西。当我进入服务器的IP地址时,我的角度应用程序就开始了:
我也可以在tomcat上运行我的spring boot应用程序。但这两个人并不同步。当我在本地计算机上运行spring app时,远程角度应用程序连接它并且运行良好。但我想用远程弹簧应用程序来运行它。
@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());
}
这是登录的请求图。
@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});
}
这是在角应用程序中登录的功能。
我应该将http://localhost:8181/token更改为http://138.68.76.62:8181/token吗?
答案 0 :(得分:0)
只需将其更改为/
@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});
}
答案 1 :(得分:0)
使用相对路径和&#34; /&#34;
示例:
绝对路径:
let url = "http://localhost:8181/token";
相对路径:
let url = "/token";