Files
bun.sh/examples/openInEditor.js
Colin McDonnell d265ed80d2 Docs for Bun.password and ws publish (#3227)
* Update websocket docs & jsdoc

* Document Bun.password

* Update hash encoding docs

* Fix typos

* Add info about user-specific data in ws

* Update outdated websocket jsdoc

* Replace usages of req.url

* Remove log
2023-06-06 23:50:43 -07:00

24 lines
578 B
JavaScript

import { resolve } from "path";
import { parse } from "querystring";
export default {
fetch(req) {
const url = new URL(req.url);
if (url.pathname === "/favicon.ico") return new Response("nooo dont open favicon in editor", { status: 404 });
var pathname = req.url.substring(1);
const q = pathname.indexOf("?");
var { editor } = parse(pathname.substring(q + 1)) || {};
if (q > 0) {
pathname = pathname.substring(0, q);
}
Bun.openInEditor(resolve(pathname), {
editor,
});
return new Response(`Opened ${req.url}`);
},
};