简体   繁体   English

Angular 7 无法解析 spring 启动 rest ZDB974238714CA8DE634A7CE1D08 主机名

[英]Angular 7 Unable to resolve spring boot rest API hostname

I have bundled an Angular7 app as static content within a spring boot REST API into a.war archive and deployed it on JBoss EAP 7.3. I have bundled an Angular7 app as static content within a spring boot REST API into a.war archive and deployed it on JBoss EAP 7.3. The application deploys successfully and I am able to see the login page.应用程序部署成功,我可以看到登录页面。 However, when I try to login, I get a net::err_name_not_resolved error in my browser console and when I check the network tab, I see that the hostname is omitted whilst angular is trying to call the REST API for authentication, hence the error reported in the console. However, when I try to login, I get a net::err_name_not_resolved error in my browser console and when I check the network tab, I see that the hostname is omitted whilst angular is trying to call the REST API for authentication, hence the error在控制台中报告。 In my angular configs, I have defined apiHost='/' and expect that this would be resolved to the machine's host or IP at runtime, but this is not working.在我的 angular 配置中,我定义apiHost='/'并希望这将在运行时解析为机器的主机或 IP,但这不起作用。 I have also created a jboss-web.xml where I defined the context root as / .我还创建了一个 jboss-web.xml ,其中我将上下文根定义为/

I would greatly appreciate any help in this regard.我将不胜感激在这方面的任何帮助。

EDIT编辑

I need this to work because I am deploying the.war file in a JBoss cluster, hence, the application should be reachable from any of the cluster members.我需要它来工作,因为我正在 JBoss 集群中部署 .war 文件,因此,应该可以从任何集群成员访问该应用程序。

In my angular configs, I have defined apiHost='/' and expect that this would be resolved to the machine's host or IP at runtime在我的 angular 配置中,我定义了 apiHost='/' 并希望这将在运行时解析为机器的主机或 IP

You have just loaded some static files (html, js) in your server that spring boot run.您刚刚在 spring 引导运行的服务器中加载了一些 static 文件(html、js)。 Those static files (representing the frontend) are then served to the client.然后将那些 static 文件(代表前端)提供给客户端。 The client can be anyone.客户可以是任何人。

So if server runs on ip 192.168.1.1 the client can have the same or a completely different IP.因此,如果服务器在 ip 192.168.1.1 上运行,则客户端可以具有相同或完全不同的 IP。 Therefore you must provide that info.因此,您必须提供该信息。

Think of it in a simple way.以一种简单的方式考虑它。 Those html and js files are handled only by your browser which doesn't know anything about the spring boot server.那些 html 和 js 文件仅由您的浏览器处理,该浏览器对 spring 引导服务器一无所知。 Somehow the call that is invoked in those html, js files must specify where the server is.不知何故,在那些 html 中调用的调用,js 文件必须指定服务器的位置。

Therefore your apiHost='/' is wrong.因此,您的apiHost='/'是错误的。 It could be apiHost='localhost' or apiHost='some Specific Ip'它可能是apiHost='localhost'apiHost='some Specific Ip'

I finally resolved the issue by using apiHost='.'我终于通过使用apiHost='.'解决了这个问题。

I can now call up my application using any of the hosts participating in the JBoss cluster.我现在可以使用参与 JBoss 集群的任何主机调用我的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM