node.js - WeChat applet background apache reverse proxy nodejs, when uploading invalid files, returns an error response?
高洛峰
高洛峰 2017-05-16 13:26:14
0
1
896

WeChat development tools return to normal

{ code: 2, msg: 'Invalid file' }

WeChat client returns

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 framework

koa-multer middleware, processing uploaded files

When the file is too large or has the wrong type, an error is thrown

Error handling middleware

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教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
洪涛

I found the reason, it is related to pm2. It restarts as soon as an error is thrown, and catch is useless. WeChat development tools and clients, and network processing should be different

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!