how to absolute URLs using fetch in next 13?

This is how i wanna use the fetch:
const api_endpoint = "http://localhost:3000"
const api_endpoint = "http://localhost:3000"
await fetch(api_endpoint.concat("/api/posts/bids"), {
headers,
method: "POST",
body: JSON.stringify({ post_id, value }),
})
await fetch(api_endpoint.concat("/api/posts/bids"), {
headers,
method: "POST",
body: JSON.stringify({ post_id, value }),
})
But this way he is doing the fetch request to this weird endpoint: http://localhost:3000/post/undefined/api/posts/bids --- Using "relative" url solves the problem:
await fetch("/api/posts/bids", {
headers,
method: "POST",
body: JSON.stringify({ post_id, value }),
})
await fetch("/api/posts/bids", {
headers,
method: "POST",
body: JSON.stringify({ post_id, value }),
})
I assume this is a Next 13 doing, but this isn't how i'm supposed to do once i have a different baseUrl based on app environment, in case i need to use an external backend api this won't be ideal. How can i switch back to default fetch URL behavior? i'm using app directory, and this issue only happens on CLIENT COMPONENTS
0 Replies
No replies yetBe the first to reply to this messageJoin