我需要为我的网站上的一些API调用增加最大https头大小.当我运行有问题的函数时,我得到这个错误:
Server responded with status code 431. See https://vitejs.dev/guide/troubleshooting.html#_431-request-header-fields-too-large.
然而,如果我只是减少输入的长度,它就会非常好地工作. 这不是cookie问题,我只是发回一个非常大的字符串(想想一篇长文章),但当它达到一定大小时,它不再允许用户提交它.所以我需要使用终端提供的链接中列出的选项(https://vitejs.dev/guide/troubleshooting.html#_431-request-header-fields-too-large)来增加最大-http-header-size.然而,我不知道该在哪里做这件事.
在Package.json中,有一个包含以下内容的脚本部分:
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
启动脚本为"nPM run dev".所以我try 简单地修改"dev"启动脚本:
"scripts": {
"dev": "vite NODE_OPTIONS=--max_http_header_size=128000",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
这不起作用,网站根本不起作用.所以我try 修改启动脚本:
npm run dev
致:
npu NODE_OPTIONS=--max_http_header_size=128000 run dev
但这也不起作用.我只需要知道在使用vite时如何设置max_http_header_size的NODE_OPTION,因为"vite"将"note"替换为要运行的二进制文件.对于常规的React-JS网站,启动脚本是" node ",您可以简单地将NODE_OPTIONS放在其后面.但由于我们使用Vite,启动脚本不是" node ",并且在"vite"后面添加NODE_OPTIONS是行不通的.