部署后 Angular 代码未在服务器上运行

标签 angular tomcat

我正在使用 angular 8

当我使用“ng build”或“ng build --prod true”在本地构建我的项目时,它工作正常。

   local URL is http://localhost:4200/apw/

但是当我在服务器上部署我的代码时(服务器正在使用 maven angular 插件来构建和部署代码),它不起作用(就像我使用 tomcat 服务器运行构建时一样) 并在 https://ciigate.apexxfintech.com/apw/ 上运行代码

它在控制台中显示错误,无法找到主要文件,如 main.js、pollyfills.ts、runtime.js 等。 所以在 https://ciigate.apexxfintech.com/apw/ 上什么也没有显示

enter image description here

这是我的index.html

 <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
  <title>Apexx Portal</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link href="//netdna.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <!-- material icons import-->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body style="margin: 0px">
  <app-root></app-root>
</body>
</html>

如果您需要任何其他信息,请告诉我

最佳答案

我认为您收到的错误是因为您没有像这样在 angular.json 文件中定义正确的路径:

示例 Angular.JSON 片段

"options": {
            "outputPath": "dist",
            "index": "src/index.html",   //Define your main,runtime,polyfills routes here
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico",
              "src/manifest.webmanifest"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/scss/bootstrap.scss",
              "src/assets/scss/paper-dashboard.scss",
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/bootstrap/dist/css/bootstrap.css",
              "node_modules/font-awesome/css/font-awesome.min.css"
            ],
            "scripts": [
              "node_modules/bootstrap/dist/js/bootstrap.js"
            ]
          },

更新文件后再次执行 build --prod 然后部署它。

关于部署后 Angular 代码未在服务器上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58521615/

相关文章:

java - java 和 Angular 项目如何工作并相互通信?

angular - 从 Firestore 中检索数据作为 json

Tomcat 在 Fedora 上将端口更改为 80

java - HTTP 状态 500 - Servlet 示例 API 的 Servlet.init() 在尝试使用 Jersey 返回 JSON 对象时抛出异常

java - 取消部署时删除的上下文

tomcat - PermGen 问题 - Groovy GString 实习生字符串吗?

Angular 4 : Route Transition Loading

Angular 2 身份验证 : logout stays in the user page

javascript - Typescript:无法在构造函数中使用 : 符号编译文件

Spring Boot + Spring Security + Tomcat = 在应用程序上下文中找不到可见的 WebSecurityExpressionHandler 实例