From 81eb47de0eb08081ed0677b71aa47e9a2b473cab Mon Sep 17 00:00:00 2001 From: Jarred SUmner Date: Wed, 6 Apr 2022 01:52:15 -0700 Subject: [bun.js] Add stdout, stderr, stdin to Bun and support sendfile() + splice() --- examples/openInEditor.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/openInEditor.js (limited to 'examples/openInEditor.js') diff --git a/examples/openInEditor.js b/examples/openInEditor.js new file mode 100644 index 000000000..59282c098 --- /dev/null +++ b/examples/openInEditor.js @@ -0,0 +1,23 @@ +import { resolve } from "path"; +import { parse } from "querystring"; + +export default { + fetch(req) { + if (req.url === "/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}`); + }, +}; -- cgit v1.2.3