jkyberneees / low-http-server

HTTP Server implementation in top of uWebSocket.js
MIT License
50 stars 7 forks source link

Unhandled promise exceptions #16

Open toonvd opened 3 years ago

toonvd commented 3 years ago

Hi

When using this lib combined with restana and fast-proxy, I get the following warnings:

(node:2393512) UnhandledPromiseRejectionWarning: [object Object]
(node:2393512) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2393512) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I can't seem to pinpoint the cause of it but it only happens when I this lib as the server:

#!/usr/bin/nodejs
'use strict';

const vhostIP = process.env.VHOSTIP;
const server = require('low-http-server')();
const pump = require('pump');
const { proxy } = require('fast-proxy')({
    base: `http://${vhostIP}:7080`,
    undici: true
});
const gateway = require('restana')({
    server: server,
    prioRequestsProcessing: false
});

gateway.all('/*', function (req, res) {
    proxy(req, res, req.url, {
        rewriteRequestHeaders(req, headers) {
            delete headers.connection
            headers.host = headers['x-forwarded-host'];
            return headers
        },
        async onResponse(req, res, stream) {
            pump(stream, res)
        }
    });
});

gateway.start(8085);

I was also wondering if adding low-http-server to this setup would have any impact since the proxy / undici would probably become the bottleneck?

SaltFish001 commented 1 year ago

You should use server.listen(8085) instead gateway.start(8085)