我想在 Cloud Foundry 上部署一个 Node.JS 应用程序。我遵循以下步骤:
在 package.json 中添加引擎部分
{ "name": "vsapc", "version": "1.0.0", "description": "Application Name", "main": "server/app.js", "scripts": { "start": "node server/app.js", "backup": "node backup.js", "restore": "node restore.js", "seed": "node server/seed/Seed.js", "postinstall": "node install.js" }, "directories": { "test": "test" }, "dependencies": { "bcrypt-nodejs": "0.0.3", "body-parser": "^1.15.2", "cfenv": "^1.0.3", "express": "^4.14.0", "jsonwebtoken": "^7.1.9", "mongodb": "^2.2.5", "mongoose": "^4.6.3", "mongoose-seed": "^0.3.1", "morgan": "^1.7.0", "promise": "^7.1.1", "prompt": "^1.0.0", "winston": "^2.2.0", "winston-daily-rotate-file": "^1.4.0" }, "engines": { "node": "6.11.*", "npm": "5.*" }, "author": "", "license": "ISC" }
我创建 manifest.yml
--- applications: - name: Policy_Studio memory: 2048MB env: NODE_ENV: production
- 我在 install.js 中使用以下连接:
const vcapServices = JSON.parse(process.env.VCAP_SERVICES); let mongoUrl = ''; mongoUrl = vcapServices.mongodb[0].credentials.uri; mongoose.connect(mongoUrl,{useMongoClient: true}, function (err){ if (err) { console.log("Database connection responded with: " + err.message); console.log("Is your server.config.json up to date?"); process.exit(1); return } console.log("Connected to database.");
- 以及 app.js 中的以下内容:
Server.prototype.connectDatabase = function (url) { mongoose.Promise = Promise; const vcapServices = JSON.parse(process.env.VCAP_SERVICES); let mongoUrl = ''; mongoUrl = vcapServices.mongodb[0].credentials.uri; mongoose.connect(mongoUrl,{useMongoClient: true}); mongoose.connection.on("error", function (err) { log.error(err) }); mongoose.connection.once("openUri", function () { log.info("Connected to DB") }) };
通过命令行连接到 SCAPP 并使用 cf push 推送应用程序
因为我没有云上的 MongoDB,所以我有一个错误
我在云上搭建了一个mongodb服务,通过web GUI直接绑定app
- 在 gui 我单击我的应用程序的重新暂存按钮
- 我有错误
Database connection responded with: failed to connect to server [2xtorvw9ys7tg9pc.service.consul:49642] on first connect [MongoError: connect ECONNREFUSED 10.98.250.54:49642]
- 我在清单中添加服务 mongoDB 并 cf push 我的应用程序
仍然与第 9 点相同的错误
我试图更改 install.js 中的连接
感谢您的帮助