At nuxtjs poroject, I have a configure variable of api environment like this:
[
{
front_host: local-1.domain.com,
backend_api: api-1.domain.com
},
{
front_host: local-2.domain.com,
backend_api: api-2.domain.com
},
]
I need get the right object element from the host name, for example, if the host name of my web page is "local-1.domain.name", then I shall get the object {front_host: local-1.domain.com, backend_api: api-2.domain.com}
.
In nuxtjs, if the web page renders at the front end, then I can get host name by location.host
, if at ssr(server side rendering), how can I get the host name?
Like@divine said, there are several options you could choose from.
For example,
export default {
async asyncData ({ req, res }) {
if (process.server) {
return { host: req.headers.host }
}
}
host will be your ssr host name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With