Nextjs Failed to proxy URL Error: socket

210 阅读1分钟

最近在调试接口时,发现代理到后端的接口最多只能有30秒的超时,如果接口30秒没有返回数据,nextjs就会中断接口,主动返回Internal Server error,去找了一下nextjs文档,发现并没有配置timeout的地方,后来在issue中才找到解决的办法。

原来在next.js/packages/ne… 中,timeout默认被设置成了30秒。

const proxy = new HttpProxy({ 
   target, 
   changeOrigin: true, 
   ignorePath: true, 
   xfwd: true, 
   proxyTimeout: 30_000, // limit proxying to 30 seconds 
 }) 

在最新的nextjs中,修复了这个bug,但是没有在文档中提示。

const proxy = new HttpProxy({ 
   target, 
   changeOrigin: true, 
   ignorePath: true, 
   xfwd: true, 
   proxyTimeout: this.nextConfig.experimental.proxyTimeout || 30_000, // limit proxying to 30 seconds 
 }) 

next.config.js 超时改为300秒

const nextConfig = {
  experimental: {
    proxyTimeout: 300_000,
  },
};

module.exports = nextConfig;

原地址:

github.com/vercel/next…

github.com/vercel/next…