unjs / httpxy

🔀 A Full-Featured HTTP and WebSocket Proxy for Node.js
Other
194 stars 12 forks source link

All unjs official code base documentation is very poor #41

Closed allmors closed 8 months ago

allmors commented 8 months ago

Describe the change

import { createServer } from "node:http";

import { createProxyServer } from "httpxy";

const proxy = createProxyServer({});

const server = createServer(async (req, res) => {
  try {
    await proxy.web(req, res, {
      target: main.url,
    });
  } catch (error) {
    console.error(error);
    res.statusCode = 500;
    res.end("Proxy error: " + error.toString());
  }
});

server.listen(3000, () => {
  console.log("Proxy is listening on http://localhost:3000");
});

The above code runs with an error image image

URLs

No response

Additional information