将 approuter 部署到 Cloud Foundry 后,应用程序崩溃了

After deploying the approuter to cloud foundry, the app is getting crashed

我遵循了这方面的步骤 blog 并部署了我将 approuter 部署到 Cloud Foundry 之后,应用程序崩溃了。

错误日志如下。

2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! Linux 4.4.0-111-generic
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! argv “/home/vcap/deps/0/node/bin/node” “/home/vcap/deps/0/bin/npm” “start”
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! node v6.13.1
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! npm v3.10.10
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! path /home/vcap/app/package.json
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! code ENOENT
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! errno -2
2018-04-11T15:26:11.61-0400 [APP/PROC/WEB/0] ERR npm ERR! syscall open
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! enoent ENOENT: no such file or directory, open ‘/home/vcap/app/package.json’
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! enoent ENOENT: no such file or directory, open ‘/home/vcap/app/package.json’
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! enoent This is most likely not a problem with npm itself
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! enoent and is related to npm not being able to find a file.
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! enoent
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! Please include the following file with any support request:
2018-04-11T15:26:11.62-0400 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/npm-debug.log

错误日志显示 package.json 文件丢失,但我将 package.json 文件放在 approuter 目录中。

下面是 manifest.json 文件中的代码。

---
applications:
 - name: approuter
   host: approuter-s0018349215trial
   path: approuter
   memory: 128M
   buildpack: nodejs_buildpack
   env:
        TENANT_HOST_PATTERN: '*****'
        destinations: '[{"name":"Businesspartners_cloudfoundry", "url" 
        :"https://***********", "forwardAuthToken": true}]'
   services:
     - my-xsuaa

下面是 package.json 文件

{
  "name": "@sap/approuter",
  "description": "Node.js based application router",
  "version": "2.10.0",
  "repository": {},
  "main": "approuter.js",
  "dependencies": {
    "agentkeepalive": "2.0.5",
    "async": "2.0.1",
    "basic-auth": "1.0.3",
    "commander": "2.9.0",
    "compression": "1.6.0",
    "connect": "3.6.2",
    "cookie": "0.2.2",
    "cookie-parser": "1.3.5",
    "cookie-signature": "1.0.6",
    "express-session": "1.15.3",
    "http-proxy-agent": "1.0.0",
    "https-proxy-agent": "1.0.0",
    "jwt-decode": "2.0.1",
    "lodash": "4.17.4",
    "lru-cache": "4.0.0",
    "mustache": "2.2.1",
    "passport": "0.3.2",
    "request": "2.81.0",
    "request-stats": "2.0.1",
    "safe-regex": "1.1.0",
    "@sap/audit-logging": "^1.0.5",
    "@sap/e2e-trace": "^1.1.2",
    "@sap/logging": "^3.0.0",
    "@sap/xsenv": "^1.2.6",
    "send": "0.15.3",
    "serve-static": "1.12.3",
    "tough-cookie": "2.3.1",
    "tv4": "1.2.7",
    "urijs": "1.16.1",
    "verror": "1.10.0",
    "ws": "1.1.4",
    "base64-url": "1.2.1",
    "scmp": "1.0.0",
    "uid-safe": "~2.0.0"
  },
  "devDependencies": {
    "body-parser": "1.15.2",
    "chai": "3.5.0",
    "diveSync": "0.3.0",
    "eslint": "3.2.2",
    "filter-node-package": "^2.0.0",
    "istanbul": "0.4.4",
    "markdown-toc": "^1.1.0",
    "mocha": "3.0.2",
    "node-build": "^1.0.0",
    "node-mocks-http": "1.5.2",
    "node-style": "^2.0.0",
    "proxyquire": "1.7.10",
    "rimraf": "2.5.4",
    "sinon": "1.17.5",
    "supertest": "2.0.0"
  },
  "engines": {
    "node": "^0.12.7 || ^4.4.0 || ^6.0.0"
  },
  "files": [
    "lib",
    "doc",
    "package.json",
    "README.md",
    "approuter.js"
  ],
  "scripts": {
    "start": "node approuter.js",
    "test": "node build/test",
    "lint": "eslint -c node_modules/node-style/.eslintrc -f stylish lib/ approuter.js",
    "toc": "markdown-toc -i README.md && markdown-toc -i doc/extending.md && markdown-toc -i doc/sizingGuide.md",
    "prepareRelease": "node build/delete-extra-packages.js && clean-packages && npm prune --production"
  }
}

下面是工作目录的截图。

下面是approuter目录的截图

使用以下错误日志部署 cf push 命令时出现不同的错误。

2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR /home/vcap/app/lib/utils/JsonValidator.js:30
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR throw new VError('%s%s: %s', 2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR ^ 2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR VError: environment-settings/tenantHostPattern: Format validation failed (regular expression must contain a capturing group)
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at JsonValidator.validate (/home/vcap/app/lib/utils/JsonValidator.js:30:11)
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Object.validateEnvironmentSettings (/home/vcap/app/lib/configuration/validators.js:106:15)
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at loadGroupedConfigurations (/home/vcap/app/lib/configuration/env-config.js:146:14)
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Object.load (/home/vcap/app/lib/configuration/env-config.js:28:17)
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Object.module.exports.load (/home/vcap/app/lib/configuration.js:15:37) 2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at bootstrap (/home/vcap/app/lib/bootstrap.js:47:36) 2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Approuter.start (/home/vcap/app/approuter.js:58:13) 2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Object. (/home/vcap/app/approuter.js:115:6) 2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Module._compile (module.js:577:32)
2018-04-23T09:27:34.02-0400 [APP/PROC/WEB/0] ERR at Object.Module._extensions..js (module.js:586:10)
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! Linux 4.4.0-116-generic 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! argv "/home/vcap/deps/0/node/bin/node" "/home/vcap/deps/0/bin/npm" "start" 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! node v6.13.1
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! npm v3.10.10 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! @sap/approuter@2.10.0 start: node approuter.js
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR!
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! Failed at the @sap/approuter@2.10.0 start script 'node approuter.js'.
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! Make sure you have the latest version of node.js and npm installed.
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! If you do, this is most likely a problem with the @sap/approuter package,
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! not with npm itself. 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! Tell the author that this fails on your system:
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! node approuter.js 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! You can get information on how to open an issue for this project with: 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR!
npm bugs @sap/approuter 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! Or if that isn't available, you can get their info via: 2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! npm owner ls @sap/approuter
2018-04-23T09:27:34.04-0400 [APP/PROC/WEB/0] ERR npm ERR! There is likely additional logging output above. 2018-04-23T09:27:34.05-0400 [APP/PROC/WEB/0] ERR npm ERR! Please include the following file with any support request: 2018-04-23T09:27:34.05-0400 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/npm-debug.log

下面是执行 cf push 命令的输出。

Uploading approuter... Uploading app files from: C:\Users\sanke\Desktop\favLocation\approuter Uploading 3.3M, 4197 files Done uploading OK Binding service my-xsuaa to app approuter in org P1942820265trial_trial / space dev as sankeerthnarsina@gmail.com... OK

Starting app approuter in org P1942820265trial_trial / space dev as sankeerthnarsina@gmail.com... Downloading nodejs_buildpack... Cell 09aeff0a-17aa-40ac-aee3-dcf077acd6c9 successfully created container for instance 6485e7e3-0b40-4db3-8880-dba968c55583 Downloaded nodejs_buildpack Cell 09aeff0a-17aa-40ac-aee3-dcf077acd6c9 creating container for instance 6485e7e3-0b40-4db3-8880-dba968c55583 Downloading app package... Downloaded app package (4.5M) -----> Nodejs Buildpack version 1.6.20 -----> Installing binaries engines.node (package.json): ^0.12.7 || ^4.4.0 || ^6.0.0 engines.npm (package.json): unspecified (use default) -----> Installing node 6.13.1 Download [https://buildpacks.cloudfoundry.org/dependencies/node/node-6.13.1-linux-x64-fc51b8dd.tgz] Using default npm version: 3.10.10 -----> Installing yarn 1.5.1 Download [https://buildpacks.cloudfoundry.org/dependencies/yarn/yarn-v1.5.1-cd316572.tar.gz] Installed yarn 1.5.1 -----> Creating runtime environment NODE_ENV=production NODE_HOME=/tmp/contents135652367/deps/0/node NODE_MODULES_CACHE=true NODE_VERBOSE=false NPM_CONFIG_LOGLEVEL=error NPM_CONFIG_PRODUCTION=true -----> Restoring cache Skipping cache restore (no previous cache) -----> Building dependencies Prebuild detected (node_modules already exists) Rebuilding any native modules agentkeepalive@2.0.5 /tmp/app/node_modules/agentkeepalive async@2.0.1 /tmp/app/node_modules/async lodash@4.17.4 /tmp/app/node_modules/lodash basic-auth@1.0.3 /tmp/app/node_modules/basic-auth commander@2.9.0 /tmp/app/node_modules/commander graceful-readlink@1.0.1 /tmp/app/node_modules/graceful-readlink compression@1.6.0 /tmp/app/node_modules/compression accepts@1.3.3 /tmp/app/node_modules/accepts negotiator@0.6.1 /tmp/app/node_modules/negotiator mime-types@2.1.16 /tmp/app/node_modules/mime-types mime-db@1.29.0 /tmp/app/node_modules/mime-db compressible@2.0.11 /tmp/app/node_modules/compressible vary@1.1.1 /tmp/app/node_modules/vary bytes@2.1.0 /tmp/app/node_modules/bytes on-headers@1.0.1 /tmp/app/node_modules/on-headers debug@2.2.0 /tmp/app/node_modules/compression/node_modules/debug ms@0.7.1 /tmp/app/node_modules/compression/node_modules/ms connect@3.6.2 /tmp/app/node_modules/connect debug@2.6.7 /tmp/app/node_modules/debug ms@2.0.0 /tmp/app/node_modules/ms finalhandler@1.0.3 /tmp/app/node_modules/finalhandler parseurl@1.3.1 /tmp/app/node_modules/parseurl escape-html@1.0.3 /tmp/app/node_modules/escape-html encodeurl@1.0.1 /tmp/app/node_modules/encodeurl unpipe@1.0.0 /tmp/app/node_modules/unpipe on-finished@2.3.0 /tmp/app/node_modules/on-finished ee-first@1.1.1 /tmp/app/node_modules/ee-first statuses@1.3.1 /tmp/app/node_modules/statuses utils-merge@1.0.0 /tmp/app/node_modules/utils-merge cookie@0.2.2 /tmp/app/node_modules/cookie cookie-parser@1.3.5 /tmp/app/node_modules/cookie-parser cookie-signature@1.0.6 /tmp/app/node_modules/cookie-signature cookie@0.1.3 /tmp/app/node_modules/cookie-parser/node_modules/cookie express-session@1.15.3 /tmp/app/node_modules/express-session depd@1.1.1 /tmp/app/node_modules/depd uid-safe@2.1.4 /tmp/app/node_modules/express-session/node_modules/uid-safe random-bytes@1.0.0 /tmp/app/node_modules/random-bytes crc@3.4.4 /tmp/app/node_modules/crc cookie@0.3.1 /tmp/app/node_modules/express-session/node_modules/cookie http-proxy-agent@1.0.0 /tmp/app/node_modules/http-proxy-agent agent-base@2.1.1 /tmp/app/node_modules/agent-base semver@5.0.3 /tmp/app/node_modules/semver extend@3.0.1 /tmp/app/node_modules/extend https-proxy-agent@1.0.0 /tmp/app/node_modules/https-proxy-agent jwt-decode@2.0.1 /tmp/app/node_modules/jwt-decode lru-cache@4.0.0 /tmp/app/node_modules/lru-cache pseudomap@1.0.2 /tmp/app/node_modules/pseudomap yallist@2.1.2 /tmp/app/node_modules/yallist mustache@2.2.1 /tmp/app/node_modules/mustache passport@0.3.2 /tmp/app/node_modules/passport pause@0.0.1 /tmp/app/node_modules/pause passport-strategy@1.0.0 /tmp/app/node_modules/passport-strategy request@2.81.0 /tmp/app/node_modules/request performance-now@0.2.0 /tmp/app/node_modules/performance-now stringstream@0.0.5 /tmp/app/node_modules/stringstream aws4@1.6.0 /tmp/app/node_modules/aws4 uuid@3.1.0 /tmp/app/node_modules/uuid tunnel-agent@0.6.0 /tmp/app/node_modules/tunnel-agent safe-buffer@5.1.1 /tmp/app/node_modules/safe-buffer tough-cookie@2.3.1 /tmp/app/node_modules/tough-cookie is-typedarray@1.0.0 /tmp/app/node_modules/is-typedarray http-signature@1.1.1 /tmp/app/node_modules/http-signature sshpk@1.13.1 /tmp/app/node_modules/sshpk asn1@0.2.3 /tmp/app/node_modules/asn1 getpass@0.1.7 /tmp/app/node_modules/getpass assert-plus@1.0.0 /tmp/app/node_modules/assert-plus dashdash@1.14.1 /tmp/app/node_modules/dashdash assert-plus@0.2.0 /tmp/app/node_modules/http-signature/node_modules/assert-plus jsprim@1.4.0 /tmp/app/node_modules/jsprim json-schema@0.2.3 /tmp/app/node_modules/json-schema verror@1.3.6 /tmp/app/node_modules/jsprim/node_modules/verror extsprintf@1.0.2 /tmp/app/node_modules/jsprim/node_modules/extsprintf har-validator@4.2.1 /tmp/app/node_modules/har-validator har-schema@1.0.5 /tmp/app/node_modules/har-schema ajv@4.11.8 /tmp/app/node_modules/ajv co@4.6.0 /tmp/app/node_modules/co json-stable-stringify@1.0.1 /tmp/app/node_modules/json-stable-stringify jsonify@0.0.0 /tmp/app/node_modules/jsonify aws-sign2@0.6.0 /tmp/app/node_modules/aws-sign2 hawk@3.1.3 /tmp/app/node_modules/hawk sntp@1.0.9 /tmp/app/node_modules/sntp hoek@2.16.3 /tmp/app/node_modules/hoek boom@2.10.1 /tmp/app/node_modules/boom cryptiles@2.0.5 /tmp/app/node_modules/cryptiles qs@6.4.0 /tmp/app/node_modules/qs json-stringify-safe@5.0.1 /tmp/app/node_modules/json-stringify-safe caseless@0.12.0 /tmp/app/node_modules/caseless isstream@0.1.2 /tmp/app/node_modules/isstream form-data@2.1.4 /tmp/app/node_modules/form-data asynckit@0.4.0 /tmp/app/node_modules/asynckit combined-stream@1.0.5 /tmp/app/node_modules/combined-stream delayed-stream@1.0.0 /tmp/app/node_modules/delayed-stream oauth-sign@0.8.2 /tmp/app/node_modules/oauth-sign forever-agent@0.6.1 /tmp/app/node_modules/forever-agent request-stats@2.0.1 /tmp/app/node_modules/request-stats http-headers@3.0.1 /tmp/app/node_modules/http-headers next-line@1.1.0 /tmp/app/node_modules/next-line once@1.4.0 /tmp/app/node_modules/once wrappy@1.0.2 /tmp/app/node_modules/wrappy safe-regex@1.1.0 /tmp/app/node_modules/safe-regex ret@0.1.14 /tmp/app/node_modules/ret @sap/audit-logging@1.0.5 /tmp/app/node_modules/@sap/audit-logging moment@2.15.2 /tmp/app/node_modules/moment winston@1.1.2 /tmp/app/node_modules/winston eyes@0.1.8 /tmp/app/node_modules/eyes pkginfo@0.3.1 /tmp/app/node_modules/pkginfo colors@1.0.3 /tmp/app/node_modules/colors async@1.0.0 /tmp/app/node_modules/winston/node_modules/async stack-trace@0.0.10 /tmp/app/node_modules/stack-trace cycle@1.0.3 /tmp/app/node_modules/cycle @sap/e2e-trace@1.1.3 /tmp/app/node_modules/@sap/e2e-trace @sap/logging@3.0.0 /tmp/app/node_modules/@sap/logging lodash@4.13.1 /tmp/app/node_modules/@sap/logging/node_modules/lodash @sap/xsenv@1.2.7 /tmp/app/node_modules/@sap/xsenv verror@1.10.0 /tmp/app/node_modules/verror core-util-is@1.0.2 /tmp/app/node_modules/core-util-is extsprintf@1.3.0 /tmp/app/node_modules/extsprintf send@0.15.3 /tmp/app/node_modules/send range-parser@1.2.0 /tmp/app/node_modules/range-parser http-errors@1.6.1 /tmp/app/node_modules/http-errors inherits@2.0.3 /tmp/app/node_modules/inherits depd@1.1.0 /tmp/app/node_modules/http-errors/node_modules/depd setprototypeof@1.0.3 /tmp/app/node_modules/setprototypeof etag@1.8.0 /tmp/app/node_modules/etag mime@1.3.4 /tmp/app/node_modules/mime fresh@0.5.0 /tmp/app/node_modules/fresh destroy@1.0.4 /tmp/app/node_modules/destroy serve-static@1.12.3 /tmp/app/node_modules/serve-static tv4@1.2.7 /tmp/app/node_modules/tv4 urijs@1.16.1 /tmp/app/node_modules/urijs ws@1.1.4 /tmp/app/node_modules/ws ultron@1.0.2 /tmp/app/node_modules/ultron options@0.0.6 /tmp/app/node_modules/options base64-url@1.2.1 /tmp/app/node_modules/base64-url scmp@1.0.0 /tmp/app/node_modules/scmp uid-safe@2.0.0 /tmp/app/node_modules/uid-safe bcrypt-pbkdf@1.0.1 /tmp/app/node_modules/bcrypt-pbkdf tweetnacl@0.14.5 /tmp/app/node_modules/tweetnacl ecc-jsbn@0.1.1 /tmp/app/node_modules/ecc-jsbn jsbn@0.1.1 /tmp/app/node_modules/jsbn Installing any new modules (package.json) -----> Caching build Clearing previous node cache Saving 3 cacheDirectories (default): - .npm (nothing to cache) - .cache/yarn (nothing to cache) - bower_components (nothing to cache) Exit status 0 Uploading droplet, build artifacts cache... Uploading build artifacts cache... Uploading droplet... Uploaded build artifacts cache (14.3M) Uploaded droplet (17.6M) Uploading complete Cell 09aeff0a-17aa-40ac-aee3-dcf077acd6c9 stopping instance 6485e7e3-0b40-4db3-8880-dba968c55583 Cell 09aeff0a-17aa-40ac-aee3-dcf077acd6c9 destroying container for instance 6485e7e3-0b40-4db3-8880-dba968c55583 Cell 09aeff0a-17aa-40ac-aee3-dcf077acd6c9 successfully destroyed container for instance 6485e7e3-0b40-4db3-8880-dba968c55583

0 of 1 instances running, 1 starting 0 of 1 instances running, 1 crashed FAILED Error restarting application: Start unsuccessful

有人可以帮我吗?

日志消息表明无法正确解析 TENANT_HOST_PATTERN 变量的环境变量:ERR VError: environment-settings/tenantHostPattern: Format validation failed (regular expression must contain a capturing group)

请为 manifest.yml 中的 TENANT_HOST_PATTERN 变量指定正确的正则表达式,例如 approuter-(.*).cfapps.eu10.hana.ondemand.com(请注意将域替换为您要部署到的环境)。

或者,您可以通过 cf set-env approuter TENANT_HOST_PATTERN 'approuter-(.*).cfapps.eu10.hana.ondemand.com' 后跟 cf restage approuter 命令来设置变量。