Heroku状态503应用程序崩溃

时间:2018-04-27 18:22:06

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

我从未使用过Heroku所以我不知道如何解决这个给我的错误。它导致我的iOS应用程序与Stripe集成崩溃状态代码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"
}

1 个答案:

答案 0 :(得分:1)

错误:

  

ReferenceError:app未定义

参与你的部分代码:

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