admin管理员组文章数量:1122846
I need to get the Full Host, I am creating an API endpoint at ~/server/api/test
but with event on defineEventHandler
is just giving me for example only localhost host but without port.
I am trying with getRequestURL(event)
too but same issue.
I need this because I am creating a wrapper for fetch and I need to send full host to an external multitenant API.
Can you help me how to get Full Host ?.
Previously I have Tried:
const { host } = getRequestURL(event) console.log(host)
Result: localhost
Expecting: localhost:3000
or domain.test
I need to get the Full Host, I am creating an API endpoint at ~/server/api/test
but with event on defineEventHandler
is just giving me for example only localhost host but without port.
I am trying with getRequestURL(event)
too but same issue.
I need this because I am creating a wrapper for fetch and I need to send full host to an external multitenant API.
Can you help me how to get Full Host ?.
Previously I have Tried:
const { host } = getRequestURL(event) console.log(host)
Result: localhost
Expecting: localhost:3000
or domain.test
1 Answer
Reset to default 0I found a solution:
Create composable: /composables/getHost.ts
So I can use useRequestURL()
SSR.
export const useHost = () => { const { host } = useRequestURL() return host }
So in my component or page or store I can use useFetch()
or other data fetching and call to my server endpoint /api/test
as "post" method and send body with "host" value from my composable.
So now I can use the host in /server/api/test.post.ts
to get data from external api.
I don't know if is a good approach but is it working at the moment.
本文标签: How to get the Full Host in Server Api Nuxt 3Stack Overflow
版权声明:本文标题:How to get the Full Host in Server Api Nuxt 3? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302626a1931602.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论