ios - Heroku 状态 503 应用程序崩溃

标签 ios heroku stripe-payments http-status-code-503

我从未使用过 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: 由于显而易见的原因, strip 键并不完整,但在实际代码中它是完整的。

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: app is not defined

获取部分代码:

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
}));

你在哪里实例化了变量 app ?

您在声明之前就使用了它。

您可能希望将其声明为:

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 状态 503 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50068208/

相关文章:

ReactJS:Stripe Google 和 Apple Pay

ios - 从字典数组填充表部分和行

ruby-on-rails - 带有 Heroku 的 Rails 不发送 Mandrill 电子邮件

heroku - flask / unicorn : setting environment variable from environment variable

java - 没有这样的收件人错误 Stripe

stripe-payments - 使用 Stripe.js 将卡保存给客户

ios - 使图像适合圆形 ImageView

ios - UIWebView 第一次在特定的 UIViewController 中显示时加载速度非常慢

ios - UIScrollView 不响应委托(delegate)

ruby-on-rails - 无法在 Heroku 上为我的 Rails 应用程序提供种子文件