java 在 Wildfly 中部署 Angular 应用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34395717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:50:24  来源:igfitidea点击:

Deploy Angular app in Wildfly

javaangularjsjakarta-eewildfly

提问by Mark Deno

I made an AngularJs application that just uses my REST api backend (built in java and deployed on Wildfly).

我制作了一个 AngularJs 应用程序,它只使用我的 REST api 后端(用 Java 构建并部署在 Wildfly 上)。

I made my servers accessible from the Internet using my public IP address (through port-forwarding).

我使用我的公共 IP 地址(通过端口转发)使我的服务器可以从 Internet 访问。

My question is how can I make the Angular application accessible as well from the Internet using my public IP. Can I also deploy it on Wildfly? How do i do that?

我的问题是如何使用我的公共 IP 使 Angular 应用程序也可以从 Internet 访问。我也可以在 Wildfly 上部署它吗?我怎么做?

采纳答案by Rémi Bantos

You could package your angular application in the same application as your REST backend API.

您可以将 Angular 应用程序打包在与 REST 后端 API 相同的应用程序中。

For example, if you package your REST api within a .war package, you could put your anglar application files (html pages, js scripts, ...) in your WAR package root, and your REST resources in WEB-INF/lib directories packaged as JAR files.

例如,如果您将 REST api 打包在 .war 包中,则可以将 anglar 应用程序文件(html 页面、js 脚本等)放在 WAR 包根目录中,并将 REST 资源放在 WEB-INF/lib 目录中打包为 JAR 文件。

See WAR packaging details here.

请参阅此处的WAR 包装详细信息。

Then to query your REST api, you just have to provide the resource URI, not the base URL (including webapp context), as angular app belongs to the webapp which also exposes your REST api.

然后要查询您的 REST api,您只需要提供资源 URI,而不是基本 URL(包括 webapp 上下文),因为 angular 应用程序属于 webapp,它也公开了您的 REST api。

For example, if you want to get one of your resource, you can do like this with angular: (with your REST API using 'rs' path in application config and using $http angular service)

例如,如果你想获得你的资源之一,你可以用 angular 来做:(你的 REST API 在应用程序配置中使用“rs”路径并使用 $http angular 服务)

$http.get('rs/icecreams?flavoor=strawberry')

回答by Emilio Garcia

If you don't want to deploy a WAR/EAR, try defining a handler in your standalone.xml configuration file:

如果您不想部署 WAR/EAR,请尝试在您的 standalone.xml 配置文件中定义一个处理程序:

<server name="default-server">
    <http-listener name="default" socket-binding="http"/>
    <host name="default-host" alias="localhost">
        <location name="/" handler="welcome-content"/>
        <location name="/yourapp" handler="static"/>
    </host>
</server>
<handlers>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
    <file name="static" path="/var/yourapp" directory-listing="true"/>
</handlers>

回答by Gaalvarez

I have an angular2 app whith routes, and was necessary an additional configuration. This is the process:

我有一个带有路由的 angular2 应用程序,并且需要额外的配置。这是过程:

  1. In the root module enable use hash for your routes:

    RouterModule.forRoot(routes, { useHash: true })
    
  2. Build the application, the simple way is ng buildother options in angular-cli build

  3. The build process generates angular app in "dist" folder in root of angular app. Copy all files inside dist folder to root of your WAR file.

  4. Acces to angular app in http://SERVER_IP:PORT/WAR_PATH/#/. All routes for angular app start from #/.

  1. 在根模块中,为您的路由启用散列:

    RouterModule.forRoot(routes, { useHash: true })
    
  2. 构建应用程序,简单的方法是angular-cli build中的ng build其他选项

  3. 构建过程会在 angular 应用程序根目录的“dist”文件夹中生成 angular 应用程序。将 dist 文件夹中的所有文件复制到 WAR 文件的根目录。

  4. 访问http://SERVER_IP:PORT/WAR_PATH/#/ 中的angular 应用程序。angular 应用程序的所有路由都从 #/ 开始。