使用 Node.js 最新的 API 模拟 Edge Runtime。
目前只支持 Node.js=>18.14.0
,低于此版本的无法启动项目。
$ yarn install
$ yarn dev
模拟 Deno.serve( ) API
import EdgeRuntime from "./edge-runtime";
const runtime = new EdgeRuntime();
const port = 8080;
const handler = (request: Request): Response=> {
const body = `Your user-agent is:\n\n${
request.headers.get("user-agent") ?? "Unknown"
}`;
return new Response(body, { status: 200 });
};
console.log(`HTTP server running. Access it at: http://localhost:8080/`);
runtime.serve({ port }, handler)
MIT