import { serve } from "https://deno.land/std@0.50.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
// listing to requests
for await (const req of s) {
const res = await fetch('https://api.github.com/users')
let data = await res.json()
console.log('test- call')
req.respond({ body:JSON.stringify(data)});
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,当我尝试点击http://localhost:8000/时,我可以看到控制台记录两次“test-call”。
不知道为什么会发生这种情况。需要帮助才能理解。