gpt4 book ai didi

Can't i make multiple returns using if statements?(我不能使用If语句进行多次返回吗?)

转载 作者:bug小助手 更新时间:2023-10-25 11:51:11 26 4
gpt4 key购买 nike



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})


}

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com