git - 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
解决方案
这是由错误的 package.json 引起的!
我的构建脚本也在启动服务器,而不是作为单独的命令启动构建后。
推荐阅读
- openlayers - 画布坐标与openlayers中的旋转地图
- redirect - 如何在托管在多个区域的应用程序中进行重定向
- python - 我已经按照教程中的所有内容进行操作,但它在第 6 行显示意外缩进,我该如何解决这个问题
- amazon-web-services - 是否可以使用“AmazonS3ReadOnlyAccess”策略列出所有存储桶?
- asp.net-core - 从 .net 核心中的不同站点发布时无法访问 cookie
- angularjs - 在身份验证 ASP.NET Core 5 上获取连接被拒绝错误
- node.js - 使用 nodejs 和 mongoDB 数据库进行多租户
- python-3.x - python 的 simplekml 不输出“别名”标签
- android - 更新到 gradle 7 后方法 com.android.build.gradle.internal.core.MergedFlavor#setSigningConfig 的模棱两可的方法重载
- laravel - Laravel - 注册后无法将用户重定向到特定路径