mirror of
https://github.com/186526/handlers.js
synced 2024-10-13 00:29:43 +00:00
fix types & add bun adapater (WIP)
This commit is contained in:
@ -7,6 +7,9 @@ export const platform = (() => {
|
||||
if (typeof Deno != "undefined") {
|
||||
return "Deno";
|
||||
}
|
||||
if (typeof Bun != "undefined") {
|
||||
return "Bun";
|
||||
}
|
||||
if (typeof tjs != "undefined") {
|
||||
return "txiki.js";
|
||||
}
|
||||
@ -17,7 +20,7 @@ export const platform = (() => {
|
||||
})();
|
||||
export const version = (() => {
|
||||
switch (platform) {
|
||||
case "Node.js":
|
||||
case "Node.js" || "Bun":
|
||||
return process.version;
|
||||
case "Deno":
|
||||
return Deno.version.deno;
|
||||
|
||||
20
src/platform/bun.ts
Normal file
20
src/platform/bun.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { SWPlatformAdapter } from "./serviceworker";
|
||||
import { platformAdapater } from "./index";
|
||||
|
||||
export class BunPlatformAdapter<T = any, K = any>
|
||||
extends SWPlatformAdapter<T, K>
|
||||
implements platformAdapater<T, K>
|
||||
{
|
||||
async listen(port: number): Promise<void> {
|
||||
Bun.serve({
|
||||
fetch: async (request: Request): Promise<Response> => {
|
||||
return await this.handleResponse(
|
||||
await this.handleRequest(request).then((request) =>
|
||||
this.router.respond(request)
|
||||
)
|
||||
);
|
||||
},
|
||||
port,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user