search

Home  >  Q&A  >  body text

node.js - WeChat applet background apache reverse proxy nodejs, when uploading invalid files, returns an error response?

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'
  }
}
高洛峰高洛峰2795 days ago973

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:28:14

    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

    reply
    0
  • Cancelreply