在Deno运行时使用以下简单的TypeScript代码:
import { serve } from "https://deno.land/std@v0.24.0/http/server.ts"
async function main() {
const body = new TextEncoder().encode("Hello World\n");
let port = 8000
const s = serve({ port: port });
console.log(`Server had been started at:
http://localhost:${port}/`);
for await (const req of s) {
req.respond({ body });
}
};
main()
通过运行执行:
D:\repos\deno>deno --allow-net main.ts
Compile file:///D:/repos/deno/main.ts
Server had been started at:
http://localhost:8000/
Hello World
在浏览器中显示 a 。
有没有办法显示 HTML 元素而不是文本,例如显示<h1>
或<button>