我正在将我的nodejs版本从8升级到10。升级后,我现在无法在任何浏览器中运行我的应用程序。所以我用谷歌搜索了我的问题,发现 Node 10 的 header 大小已从 80kb 缩小到 8kb。我的应用程序 header 大小超过 8kb。所以我需要使用nodejs命令--max-http-header-size=80000
来设置它。但我不知道如何使用 nodemon
和 babel-node
设置它。
请帮忙。
这是我的nodemon.json
{
"ext": "js jsx ejs json gql css",
"exec": "babel-node"
}
这是我当前的 package.json:
"develop:server": "BABEL_ENV=server nodemon .",
我已经尝试过的解决方案:
{
"ext": "js jsx ejs json gql css",
"exec": "node --max-http-header-size=80000 ./node_modules/babel-cli/bin/babel-node.js"
}
正确的解决方案如下(选择其中之一):
-
{ "ext": "js jsx ejs json gql css", "exec": "NODE_OPTIONS=--max-http-header-size=80000 babel-node" }
"develop:server": "NODE_OPTIONS=--max-http-header-size=80000 BABEL_ENV=服务器 nodemon 。",
最佳答案
我认为 Node 工程师从版本8.16.0
减少了http-header-size
。他们减少了它以防止像 DDOS 等攻击。当我从 Node 版本 8.9.1 升级到 8.16.0 时,我遇到了同样的问题。我如何解决这个问题是在我的 package.json
中,我添加了 --max-http-header-size=80000
flag in start script
例如
"scripts": {"start": "node --max-http-header-size=80000 server.js"}
并且成功了。但如果您的 header 超过 8kb,那么您必须返回到以前的版本,直到出现正确的修复程序。
关于node.js - 如何使用 `--max-http-header-size` babel-node 设置 nodejs 命令 `nodemon --exec "。`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57705290/