【发布时间】:2018-10-31 13:08:54
【问题描述】:
我有一个网站在我的本地机器上运行,我想将此应用程序部署到 DigitalOcean。我创建了一个液滴,安装了必要的东西。当我输入服务器的 IP 地址时,我的 Angular 应用程序启动:
我还可以在 tomcat 上运行我的 Spring Boot 应用程序。但是这两个不同步运行。当我在本地机器上运行 spring 应用程序时,远程 Angular 应用程序连接它并运行良好。但我想用远程 spring 应用程序运行它。
@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});
}
这是 Angular 应用中的登录功能。
我应该将http://localhost:8181/token 更改为http://138.68.76.62:8181/token 之类的吗?
【问题讨论】:
标签: angular spring-boot tomcat digital-ocean