Skip to content

bun-compat: expose Bun.serve over Perry's native HTTP server #9603

Description

@proggeramlug

Summary

Implement a Bun-compatible serve facade over Perry's existing native HTTP/HTTPS stack. This is a synthetic parity target, independent of any application corpus.

Minimal fixture

import { serve } from "bun";

const server = serve({
  hostname: "127.0.0.1",
  port: 0,
  idleTimeout: 0,
  development: false,
  fetch(request, server) {
    const address = server.requestIP(request)?.address ?? "unknown";
    return new Response(`${request.method}:${address}`);
  },
  error(error) {
    return new Response(error.message, { status: 500 });
  },
});

console.log(server.hostname, server.port > 0);
const response = await fetch(`http://127.0.0.1:${server.port}/`);
console.log(response.status, await response.text());
server.unref();
server.stop(true);

Initial acceptance surface

  • ephemeral port: 0, hostname binding, hostname and port properties;
  • Fetch API request/response handler, async handlers, and error handler;
  • requestIP(request);
  • stop(closeActiveConnections?), ref, and unref;
  • TLS options can be a follow-up if a clear unsupported diagnostic is emitted.

A Bun-native CLI has two reachable call sites: a loopback MCP server in a normal plugin path and a gateway HTTP server using requestIP, TLS options, idleTimeout, and stop(true).

Official API: https://bun.sh/docs/runtime/http/server.

Current Perry lowers neither Bun.serve nor an equivalent named export from "bun". Verified at 898e531590d874923314e48cf11950fc47c7f098.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew capability or improvementparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystem

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions