首页 > 解决方案 > Express 应用程序挂在 git push to Heroku 上

问题描述

我正在运行一个处理 NextJS 应用程序路由的 Express 应用程序。在代码中,我在最后运行 listen ,这是我将应用程序推送到 Heroku 时看到的最后一件事。

要推送应用程序,我目前正在做的只是提交整个目录并推送到 Heroku master。该应用程序是未编译的 Next 应用程序,其 package.json 包含:

"start": "cross-env NODE_ENV=production node server.js"

const express = require('express')
const bodyParser = require('body-parser')
const next = require('next')
const admin = require('firebase-admin')
const port = 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const config = require('./credentials/client')
const firebase = admin.initializeApp(
  ...
)

app.prepare().then(() => {
  const server = express()

  server.use(bodyParser.json())
  server.use(
    session({
      secret: 'secret',
      saveUninitialized: true,
      store: new FirebaseStore({
        database: firebase.database()
      }),
      resave: false,
      rolling: true,
      httpOnly: true,
      cookie: { maxAge: 604800000 } // week
    })
  )

  server.use((req, res, next) => {
    req.firebaseServer = firebase
    next()
  })

  server.get('*', (req, res) => {
    return handle(req, res)
  })

  server.listen(port, err => {
    if (err) throw err
    console.log(`> Ready on http://localhost:${port}`)
  })
})

这是产生的任何原因:

remote:        > Ready on http://localhost:3000
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
Everything up-to-date

标签: githerokunext.js

解决方案


这是由错误的 package.json 引起的!

我的构建脚本也在启动服务器,而不是作为单独的命令启动构建后。


推荐阅读