node.js - 微信小程序后台 apache 反向代理 nodejs ,上传无效文件时,返回错误响应?
高洛峰
高洛峰 2017-05-16 13:26:14
0
1
867

微信开发工具返回正常

{ code: 2, msg: '无效的文件' }

微信客户端返回

Bad Gateway! The proxy server received an invalid response from an
upstream server.

apache

httpd-ssl.conf

<VirtualHost _default_:443>

  ProxyPass /mina http://127.0.0.1:3000
  ProxyPassReverse /mina http://127.0.0.1:3000

  SetEnv force-proxy-request-1.0 1
  SetEnv proxy-nokeepalive 1

</VirtualHost>

node

koa 框架

koa-multer 中间件,处理上传文件

文件过大或类型错误时,抛出错误

处理错误中间件

async function errorHandler (ctx, next) {
  try {
    await next()
  }
  catch (err) {
    let msg = parseError(err)
    ctx.body = { code: 2, msg }
    ctx.type = 'application/json'
  }
}
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(1)
洪涛

找到原因了,是pm2的关系,一抛错误就重启,catch也没用,微信开发工具和客户端,网络处理应该不一样

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!