lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.21k stars 85 forks source link

Proxy: a remote hangup should not crash the server #37

Closed 75lb closed 8 years ago

75lb commented 8 years ago

if a remote proxy request fails for some reason (e.g. socket hang-up), ws crashes.. it should handle the exception, report the issue and carry on.

InternalServerError: [PROXY] socket hang up: http://lhtapp01:8180/resources/contents/copies/113864/draft?nocache=146315555730825777655849.375153
    at Object.throw (/Users/lloydb/Documents/75lb/local-web-server/node_modules/koa/lib/context.js:91:23)
    at ProxyServer.proxy.once.err (/Users/lloydb/Documents/75lb/local-web-server/lib/middleware.js:40:17)
    at ProxyServer.emit (/Users/lloydb/Documents/75lb/local-web-server/node_modules/eventemitter3/index.js:144:27)
    at ClientRequest.proxyError (/Users/lloydb/Documents/75lb/local-web-server/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:141:16)
    at emitOne (events.js:101:20)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketCloseListener (_http_client.js:282:9)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:4ecc-ui lloydb:$
75lb commented 8 years ago

another example

InternalServerError: [PROXY] getaddrinfo ENOTFOUND lhtapp01 lhtapp01:8180: http://lhtapp01:8180/resources/contents/copies/113879/draft
    at Object.throw (/Users/lloydb/Documents/75lb/local-web-server/node_modules/koa/lib/context.js:91:23)
    at ProxyServer.proxy.once.err (/Users/lloydb/Documents/75lb/local-web-server/lib/middleware.js:40:17)
    at ProxyServer.emit (/Users/lloydb/Documents/75lb/local-web-server/node_modules/eventemitter3/index.js:144:27)
    at ClientRequest.proxyError (/Users/lloydb/Documents/75lb/local-web-server/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:141:16)
    at emitOne (events.js:101:20)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:306:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at connectErrorNT (net.js:1015:8)
lanoxx commented 8 years ago

Adding a third example:

InternalServerError: [PROXY] connect ECONNREFUSED 127.0.0.1:8080: http://localhost:8080/...
    at Object.throw (/usr/local/lib/node_modules/local-web-server/node_modules/koa/lib/context.js:91:23)
    at ProxyServer.<anonymous> (/usr/local/lib/node_modules/local-web-server/lib/middleware.js:48:17)
    at ProxyServer.emit (/usr/local/lib/node_modules/local-web-server/node_modules/eventemitter3/index.js:144:27)
    at ClientRequest.proxyError (/usr/local/lib/node_modules/local-web-server/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:141:16)
    at emitOne (events.js:82:20)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketErrorListener (_http_client.js:258:9)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1256:8)

ws started with:

ws -p 8082 -r '/api/*->http://localhost:8080/$1' -d app

and the proxied app was not running or had crashed.

75lb commented 8 years ago

fixed and released in v1.2.5, thanks for the patience.

lanoxx commented 8 years ago

Perfect :-)