Angular Universal在生产服务器上不起作用

时间:2018-09-22 20:23:53

标签: angular typescript express serverside-rendering

我已经创建了一个带有Express框架的rest api应用程序,并且在客户端站点上我使用了通用角度。我已经在本地计算机上对其进行了测试,一切都很好。

[1]

将我的应用程序添加到服务器后,它无法正常运行。 服务器正在运行,客户端也在运行。

页面刷新后,数据将很快显示在站点上,并且在浏览器调试控制台中,我将看到:

  

无法加载资源:net :: ERR_CONNECTION_REFUSED

Debug Console

我使用curl来检查我的其余api服务器是否可以访问并且工作正常。

  

curl localhost:3000 / getData

有人经历过同样的经历吗?

我的package.json

{
  "name": "universal",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:ssr": "node dist/server",
    "build:client-and-server-bundles": "ng build --prod && ng run universal:server",
    "webpack:server": "webpack --config webpack.server.config.js --progress --colors"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.8",
    "@angular/cdk": "^6.4.7",
    "@angular/common": "^6.1.0",
    "@angular/compiler": "^6.1.0",
    "@angular/core": "^6.1.0",
    "@angular/forms": "^6.1.0",
    "@angular/http": "^6.1.0",
    "@angular/material": "^6.4.7",
    "@angular/platform-browser": "^6.1.0",
    "@angular/platform-browser-dynamic": "^6.1.0",
    "@angular/platform-server": "^6.1.8",
    "@angular/router": "^6.1.0",
    "@nguniversal/express-engine": "^6.1.0",
    "@nguniversal/module-map-ngfactory-loader": "^6.1.0",
    "@types/jquery": "^3.3.9",
    "@types/moment": "^2.13.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "mqtt": "*",
    "ng2-mqtt": "^0.1.2",
    "rxjs": "^6.0.0",
    "rxjs-compat": "^6.3.2",
    "semantic-ui-loader": "^2.2.3",
    "underscore": "^1.9.1",
    "window": "^4.2.5",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "~6.1.5",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "@types/underscore": "^1.8.9",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "style-loader": "^0.23.0",
    "ts-loader": "^5.1.1",
    "ts-node": "~5.0.1",
    "jsdom": "11.3.0",
    "jsdom-global": "3.0.2",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2",
    "webpack-cli": "^3.1.0"
  }
}


{
  "name": "restapi",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "tsc",
    "dev": "ts-node app.ts",
    "start": "nodemon ./dist/app.js",
    "prod": "npm run build && npm run start"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/express": "^4.16.0",
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.18.3",
    "compression": "^1.7.3",
    "connect-busboy": "0.0.2",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.3",
    "cookie-session": "^2.0.0-beta.3",
    "cors": "^2.8.4",
    "express": "^4.16.3",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.2.17",
    "mosca": "^2.8.3",
    "multer": "^1.3.1",
    "nodemailer": "^4.6.8",
    "nodemailer-smtp-transport": "^2.7.4",
    "nodemon": "^1.18.4",
    "passport": "^0.4.0",
    "passport-facebook": "^2.1.1",
    "passport-google-oauth": "^0.1.5",
    "passport-http-bearer": "^1.0.1",
    "passport-local": "~1.0.0",
    "path": "^0.12.7"
  },
  "devDependencies": {
    "tslint": "^5.11.0"
  }
}

解决方案:

我发现3000端口不是空闲的。我使用sudo ufw allow3000。我使用Ubuntu作为发行版。

0 个答案:

没有答案