简体   繁体   English

如何将Angular与Liberty WebSphere Server一起使用

[英]How to use Angular with Liberty WebSphere Server

I have a project at work that uses AngularJS + JSP on a Liberty WebSphere Server 17.0.0.2 and now I have to make an upgrade on it. 我有一个在Liberty WebSphere Server 17.0.0.2上使用AngularJS + JSP的项目,现在我必须对它进行升级。 The project needs to be upgraded to Angular 4 + Liberty and I have no idea on how to do it properly. 该项目需要升级到Angular 4 + Liberty,我不知道如何正确地完成它。

What I have tried by now is: 我现在尝试的是:

Built the project with Angular-CLI to generate the dist folder. 使用Angular-CLI构建项目以生成dist文件夹。 Then, I have put the dist on WEB-INF > views . 然后,我把dist放在WEB-INF > 视图上 I have also made the references on spring-context.xml, web.xml and server.xml (on Liberty side) but all I get is a 404 error when trying to access localhost:9090/AngularPoC/dist/index 我还在spring-context.xml,web.xml和server.xml(在Liberty端)上做了引用,但是当我尝试访问localhost时,我得到的是404错误:9090 / AngularPoC / dist / index

Thank you in advance. 先感谢您。

I'll write up an overview of how I set up my Angular app(s) to be served via (Open)Liberty: 我将概述如何通过(Open)Liberty设置我的Angular应用程序:

  1. Copy product of the ng build command to the root of the .war file. ng build命令的产品复制到.war文件的根目录。 This means putting it in a different location depending on how you do your build. 这意味着根据您的构建方式将其放在不同的位置。 If you are using Eclipse/WDT that probably means setting output to be your WebContent folder. 如果您使用的是Eclipse / WDT,则可能意味着将输出设置为WebContent文件夹。 If you are using Gradle with the war plugin, it goes right into src/main/webapp . 如果你正在使用带有war插件的Gradle,它会直接进入src/main/webapp While initially I set the output folder with ng build --output-dir=... I found that this deletes the folder, so I was losing my web.xml with each build. 虽然我最初使用ng build --output-dir=...设置输出文件夹ng build --output-dir=...我发现这会删除文件夹,因此我在每次构建时丢失了我的web.xml。 I would recommend copying the contents of dist in a later step of your build unless you are okay serving from a subfolder of the context root. 我建议在构建的后续步骤中复制dist的内容,除非您可以从上下文根的子文件夹中提供服务。

  2. Set up error redirection for deep links. 为深层链接设置错误重定向。 If you use the Angular Router module, you'll need to set up linking and refreshing deep routes. 如果使用Angular Router模块,则需要设置链接和刷新深层路由。 By default, Liberty gives a 404 error page for any path that doesn't exist. 默认情况下,Liberty为任何不存在的路径提供404错误页面。 If a user refreshes the page when the URL bar contains a deep route into your application, they'll get that error page. 如果用户在URL栏包含进入应用程序的深层路径时刷新页面,他们将获得该错误页面。 You'll need to set it up so that all 404 requests are routed back to your index.html ( location should usually point to the same place as base-href , see below.) In web.xml, I have 您需要对其进行设置,以便将所有404请求路由回index.htmllocation通常应指向与base-href相同的位置,请参阅下文。)在web.xml中,我有

     <error-page> <error-code>404</error-code> <location>/</location> </error-page> 

    Another option is to use the HashLocationStrategy which uses the older anchor syntax. 另一种选择是使用HashLocationStrategy ,它使用较旧的锚语法。 The route is placed in the hash fragment of the URL. 路由放在URL的哈希片段中。 This means you don't have to set up the error page, but it also means that you won't be able to replace a deep route with a separate page seamlessly in the future--people would have to update bookmarks if they have any. 这意味着您不必设置错误页面,但这也意味着您将来无法使用单独的页面无法替换深层路由 - 如果有任何书签,人们将不得不更新书签。

    This is done by updating your app-routing.module.ts file to specify RouterModule.forRoot(routes, {useHash: true}) on the imports line. 这是通过更新app-routing.module.ts文件以在导入行上指定RouterModule.forRoot(routes, {useHash: true})来完成的。

  3. Ensure base-href matches. 确保base-href匹配。 Make sure the base-href in your index.html points to the path containing that index.html and your generated CSS and JS files from the build. 确保index.htmlbase-href指向包含该index.html的路径以及从构建中生成的CSS和JS文件。 Otherwise you'll notice nothing loads and you get a bunch of 404s in your web inspector. 否则你会发现没有任何负载,你的网络检查员会得到一堆404。 If the context-root changes, this value needs to be updated. 如果context-root发生更改,则需要更新此值。 My web app usually has the context-root / with index.html directly under it, so my base-href is / . 我的网络应用程序通常直接使用context-root / index.html,所以我的base-href/

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

相关问题 如何在Websphere上部署angular-cli应用程序? - How to deploy angular-cli app on Websphere? Angular项目(dist文件夹)部署在Websphere应用服务器 - Angular project(dist folder) deployment in Websphere Application server 是否可以在IBM Websphere Application Server上部署Angular应用程序? - Is it possible to deploy Angular app on IBM Websphere Application Server? 如何在数据服务器中使用角度材料6自动完成 - How to use angular material 6 autocomplete with data server 如何使用Angular 2服务器端渲染 - How to use Angular 2 server side rendering 如何在Angular 2中使用服务器端渲染? - How to use server-side rendering in Angular 2? 如何从远程服务器使用templateUrl? Angular 2 - How to use templateUrl from remote server? Angular 2 如何通过Angular方式示例在Angular DataTables中使用服务器端选项? - How to use server side option in Angular DataTables with the Angular way example? 如何读取配置文件以在打包为WAR并部署在IBM Liberty的Angular App中设置API URL - How to read config file to set API URL inside an Angular App packaged as a WAR and deployed on IBM Liberty Liberty server.xml和CORS设置 - Liberty server.xml and CORS settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM