Search code examples
githerokunext.js

Express app is hanging on git push to Heroku


I am running an Express app that handles the routing for a NextJS app. In the code, I'm running listen at the end and that's the last thing I see when I push my app to Heroku.

To push the app, what I'm doing currently is just committing the entire directory and pushing to Heroku master. The app is an uncompiled Next app, with a package.json with:

"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}`)
  })
})

Any reason this is yielding:

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

Solution

  • This was caused by a bad package.json!

    My build script was also starting the server, rather than starting post-build as a separate command.