香港专业教育学院从未使用过Heroku,所以我不知道如何解决这给我的错误。导致我的带有Stripe集成的iOS应用也崩溃,状态代码为503。我在这里遵循了一个教程:https://www.youtube.com/watch?v=NdszUvzroxQ,但是此错误是由于遵循它而导致的。

完整的Heroku日志:

2018-04-27T18:00:25.000000+00:00 app[api]: Build started by user nicholas.richardson.05@gmail.com
2018-04-27T18:00:35.775196+00:00 app[api]: Deploy c83c401e by user nicholas.richardson.05@gmail.com
2018-04-27T18:00:35.775196+00:00 app[api]: Release v9 created by user nicholas.richardson.05@gmail.com
2018-04-27T18:00:36.402770+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-27T18:00:25.000000+00:00 app[api]: Build succeeded
2018-04-27T18:00:38.260784+00:00 heroku[web.1]: Starting process with command `node index.js`
2018-04-27T18:00:39.892118+00:00 heroku[web.1]: Process exited with status 1
2018-04-27T18:00:39.843234+00:00 app[web.1]: /app/index.js:5
2018-04-27T18:00:39.843256+00:00 app[web.1]: app.use(bodyParser.json());
2018-04-27T18:00:39.843258+00:00 app[web.1]: ^
2018-04-27T18:00:39.843260+00:00 app[web.1]:
2018-04-27T18:00:39.843261+00:00 app[web.1]: ReferenceError: app is not defined
2018-04-27T18:00:39.843263+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:5:1)
2018-04-27T18:00:39.843264+00:00 app[web.1]:     at Module._compile (module.js:635:30)
2018-04-27T18:00:39.843266+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:646:10)
2018-04-27T18:00:39.843267+00:00 app[web.1]:     at Module.load (module.js:554:32)
2018-04-27T18:00:39.843269+00:00 app[web.1]:     at tryModuleLoad (module.js:497:12)
2018-04-27T18:00:39.843271+00:00 app[web.1]:     at Function.Module._load (module.js:489:3)
2018-04-27T18:00:39.843272+00:00 app[web.1]:     at Function.Module.runMain (module.js:676:10)
2018-04-27T18:00:39.843273+00:00 app[web.1]:     at startup (bootstrap_node.js:187:16)
2018-04-27T18:00:39.843275+00:00 app[web.1]:     at bootstrap_node.js:608:3
2018-04-27T18:00:39.965549+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-27T18:03:44.913060+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=chefev.herokuapp.com request_id=d4596f82-7f38-4f03-9845-a3357dc8fad5 fwd="174.96.153.15" dyno= connect= service= status=503 bytes= protocol=https
2018-04-27T18:03:45.482360+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=chefev.herokuapp.com request_id=3e112b2c-788b-419c-a6a5-68054a26630b fwd="174.96.153.15" dyno= connect= service= status=503 bytes= protocol=https
2018-04-27T18:11:01.502824+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-27T18:11:03.914479+00:00 heroku[web.1]: Starting process with command `node index.js`
2018-04-27T18:11:05.918942+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-27T18:11:05.829016+00:00 app[web.1]: /app/index.js:5
2018-04-27T18:11:05.829035+00:00 app[web.1]: app.use(bodyParser.json());
2018-04-27T18:11:05.829037+00:00 app[web.1]: ^
2018-04-27T18:11:05.829038+00:00 app[web.1]:
2018-04-27T18:11:05.829040+00:00 app[web.1]: ReferenceError: app is not defined
2018-04-27T18:11:05.829042+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:5:1)
2018-04-27T18:11:05.829044+00:00 app[web.1]:     at Module._compile (module.js:635:30)
2018-04-27T18:11:05.829045+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:646:10)
2018-04-27T18:11:05.829047+00:00 app[web.1]:     at Module.load (module.js:554:32)
2018-04-27T18:11:05.829049+00:00 app[web.1]:     at tryModuleLoad (module.js:497:12)
2018-04-27T18:11:05.829050+00:00 app[web.1]:     at Function.Module._load (module.js:489:3)
2018-04-27T18:11:05.829052+00:00 app[web.1]:     at Function.Module.runMain (module.js:676:10)
2018-04-27T18:11:05.829054+00:00 app[web.1]:     at startup (bootstrap_node.js:187:16)
2018-04-27T18:11:05.829055+00:00 app[web.1]:     at bootstrap_node.js:608:3
2018-04-27T18:11:05.888053+00:00 heroku[web.1]: Process exited with status 1


index.js:
由于明显的原因,条带键不完整,但是在实际代码中却是完整的。

const express = require('express')
const path = require('path')
var stripe = require('stripe')('sk_live_#');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended : true
}));

const PORT = process.env.PORT || 5000

express()
  .use(express.static(path.join(__dirname, 'public')))
  .set('views', path.join(__dirname, 'views'))
  .set('view engine', 'ejs')
  .listen(PORT, () => console.log(`Listening on ${ PORT }`))
  app.post('/ephemeral_keys', (req,res) => {
var customerId = req.body.customer_id;
var api_version = req.body.api_version;

stripe.ephemeralKeys.create({
customer : customerId},
{stripe_version : api_version}
).then((key) =>{
res.status(200).send(key)
}).catch((err) => {
res.status(500).end()
  });
});


package.json

{
  "name": "node-js-getting-started",
  "version": "0.3.0",
  "description": "A sample Node.js app using Express 4",
  "engines": {
    "node": "8.9.1"
  },
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "node test.js"
  },
  "dependencies": {
    "body-parser": "^1.18.2",
    "ejs": "^2.5.6",
    "express": "^4.16.3",
    "stripe": "^5.8.0"
  },
  "devDependencies": {
    "request": "^2.81.0",
    "tape": "^4.7.0"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/heroku/node-js-getting-started"
  },
  "keywords": [
    "node",
    "heroku",
    "express"
  ],
  "license": "MIT"
}


app.json:

{
  "name": "Start on Heroku: Node.js",
  "description": "A barebones Node.js app using Express 4",
  "repository": "https://github.com/heroku/node-js-getting-started",
  "logo": "https://cdn.rawgit.com/heroku/node-js-getting-started/master/public/node.svg",
  "keywords": ["node", "express", "heroku"],
  "image": "heroku/nodejs"
}

最佳答案

错误:


  ReferenceError:未定义应用


参与部分代码:

const express = require('express')
const path = require('path')
var stripe = require('stripe')('sk_live_#');
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended : true
}));


您在哪里实例化了变量应用程序?

您在声明之前使用它。

可能您将需要声明为:

const app = express();


您的代码应如下所示:

const express = require('express')
const path = require('path')
var stripe = require('stripe')('sk_live_#');
var bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended : true
}));
.....

关于ios - Heroku Status 503应用崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50068208/

10-11 03:01
查看更多