mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
* Add a zig fmt action * add failing file * Setup prettier better * Update prettier-fmt.yml * Fail on error * Update prettier-fmt.yml * boop * boop2 * tar.gz * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * Update zig-fmt.yml * boop * Update prettier-fmt.yml * tag * newlines * multiline * fixup * Update zig-fmt.yml * update it * fixup * both * w * Update prettier-fmt.yml * prettier all the things * Update package.json * zig fmt * ❌ ✅ * bump * . * quotes * fix prettier ignore * once more * Update prettier-fmt.yml * Update fallback.ts * consistentcy --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
// Start a fast HTTP server from a function
|
|
|
|
Bun.serve({
|
|
async fetch(req) {
|
|
const { pathname } = new URL(req.url);
|
|
if (!(pathname.startsWith("/https://") || pathname.startsWith("/http://"))) {
|
|
return new Response("Enter a path that starts with https:// or http://\n", {
|
|
status: 400,
|
|
});
|
|
}
|
|
|
|
const response = await fetch(req.url.substring("http://localhost:3000/".length), req.clone());
|
|
|
|
return new HTMLRewriter()
|
|
.on("a[href]", {
|
|
element(element) {
|
|
element.setAttribute("href", "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
|
},
|
|
})
|
|
.transform(response);
|
|
},
|
|
|
|
// this is called when fetch() throws or rejects
|
|
// error(err: Error) {
|
|
// },
|
|
|
|
// this boolean enables the bun's default error handler
|
|
// sometime after the initial release, it will auto reload as well
|
|
development: process.env.NODE_ENV !== "production",
|
|
// note: this isn't node, but for compatibility bun supports process.env + more stuff in process
|
|
|
|
// SSL is enabled if these two are set
|
|
// certFile: './cert.pem',
|
|
// keyFile: './key.pem',
|
|
|
|
port: 3000, // number or string
|
|
});
|