Here is my code:
以下是我的代码:
const server = Bun.serve({
hostname: 'localhost',
port: 8080,
fetch: handler,
});
console.log(`Listening on http://${server.hostname}:${server.port}`)
function handler(request: Request): Response {
const url = new URL(request.url)
if (url.pathname === '' || url.pathname === '/')
return new Response(Bun.file("index.html"))
return new Response("Not Found", {status: 404})
}
Here is the issue:
问题是这样的:
function handler(request: Request): Response (+1 overload)
函数处理程序(请求:请求):响应(+1重载)
Thank you
谢谢
I tried to make sure wrong links gives 404
我试着确保错误的链接给404
更多回答
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
请编辑问题以将其限制为特定问题,并提供足够的详细信息以确定适当的答案。
优秀答案推荐
You'll need {}
curly braces if you want to do a return
如果你想做回车,你需要{}个花括号
function handler(request: Request): Response {
const url = new URL(request.url)
if (url.pathname === '' || url.pathname === '/') {
return new Response(Bun.file("index.html"))
}
return new Response("Not Found", {status: 404})
}
更多回答
我是一名优秀的程序员,十分优秀!