プレイグラウンド、サンドボックス、使い捨てスクリプト置き場
0

Configure Feed

Select the types of activity you want to include in your feed.

update deno

Kohei Watanabe (Jun 17, 2025, 8:05 AM +0900) 5ceb9a6e 116a4e62

+107 -21
+1 -13
deno/deno.json
··· 1 - { 2 - "tasks": { 3 - "dev": "deno run --watch main.ts" 4 - }, 5 - "deploy": { 6 - "project": "d7ff4021-31bb-4663-b015-12a9e7b9bb64", 7 - "exclude": [ 8 - "**/node_modules" 9 - ], 10 - "include": [], 11 - "entrypoint": "main.ts" 12 - } 13 - } 1 + {}
+11
deno/deno.lock
··· 1 + { 2 + "version": "5", 3 + "specifiers": { 4 + "npm:hono@*": "4.6.14" 5 + }, 6 + "npm": { 7 + "hono@4.6.14": { 8 + "integrity": "sha512-j4VkyUp2xazGJ8eCCLN1Vm/bxdvm/j5ZuU9AIjLu9vapn2M44p9L3Ktr9Vnb2RN2QtcR/wVjZVMlT5k7GJQgPw==" 9 + } 10 + } 11 + }
+15
deno/index.html
··· 1 + <!DOCTYPE html> 2 + <html> 3 + <head> 4 + <meta charset="UTF-8" /> 5 + <meta name="viewport" content="width=device-width" /> 6 + <title>Deno Example</title> 7 + </head> 8 + <body> 9 + <h1>Deno Example</h1> 10 + <p>This is a simple HTML page served by Deno.</p> 11 + 12 + <a href="?edit">Edit This Page</a> / 13 + <a href="server.tsx?edit">Edit Server Source Code</a> 14 + </body> 15 + </html>
-8
deno/main.ts
··· 1 - const now = new Date(); 2 - 3 - if (import.meta.main) { 4 - Deno.serve(() => new Response(`${now}: Hello World!`)); 5 - } 6 - 7 - // $ curl https://great-crow-36.deno.dev/ 8 - // Mon Apr 22 2024 03:13:21 GMT+0000 (Coordinated Universal Time): Hello World!
+80
deno/server.tsx
··· 1 + #!/usr/bin/env -S deno run --watch -A 2 + /* @jsxImportSource npm:hono/jsx */ 3 + import { writeFile } from "node:fs/promises"; 4 + import { Context, Hono } from "npm:hono"; 5 + import { HTTPException } from "npm:hono/http-exception"; 6 + 7 + if (import.meta.main) { 8 + const app = new Hono(); 9 + 10 + app.get("/", (c) => c.redirect("/index.html")); 11 + app.get("/:file", async (c) => { 12 + const file = new URL(c.req.param("file"), import.meta.url).href; 13 + 14 + try { 15 + if ( 16 + c.req.header("accept")?.match(/\btext\/html\b/) && 17 + (c.req.queries("edit") || file.match(/[.][jt]sx?$/)) 18 + ) { 19 + const path = c.req.queries("edit") ? import.meta.url : file; 20 + const { default: Component } = await import(path); 21 + return c.html(Component(c)); 22 + } 23 + 24 + return await fetch(file); 25 + } catch (error) { 26 + throw new HTTPException(404, error as Error); 27 + } 28 + }); 29 + 30 + app.post("/:file", async (c) => { 31 + const file = c.req.param("file"); 32 + const body = await c.req.text(); 33 + await writeFile(file, body); 34 + return c.text("ok"); 35 + }); 36 + 37 + Deno.serve(app.fetch); 38 + } 39 + 40 + export default function EditorPage(c: Context) { 41 + return ( 42 + <html> 43 + <head> 44 + <meta charSet="utf-8" /> 45 + <title>{c.req.param("file")}</title> 46 + <script 47 + type="module" 48 + dangerouslySetInnerHTML={{ 49 + __html: `\ 50 + import { javascript } from "https://esm.sh/@codemirror/lang-javascript"; 51 + import { oneDark } from "https://esm.sh/@codemirror/theme-one-dark"; 52 + import { EditorView, basicSetup } from "https://esm.sh/codemirror"; 53 + 54 + const code = await fetch(document.location.href).then(r => r.text()); 55 + 56 + const view = new EditorView({ 57 + doc: code, 58 + extensions: [ 59 + basicSetup, 60 + oneDark, 61 + javascript({ jsx: true, typescript: true }), 62 + ], 63 + parent: document.body, 64 + }); 65 + 66 + addEventListener("keydown", async e => { 67 + if ((e.ctrlKey || e.metaKey) && e.key === "s") { 68 + e.preventDefault(); 69 + await fetch(document.location.href, { method: "POST", body: view.state.doc.toString() }); 70 + location.reload(); 71 + } 72 + }); 73 + `, 74 + }} 75 + /> 76 + </head> 77 + <body></body> 78 + </html> 79 + ); 80 + }