Accessing the request object in nuxtJS module

Viewed 323

I'm trying to create a nuxtJS module to make some changes to the routes based on the URL or request, i simply want to access the request.header.host inside a nuxtJS module but I'm unable to get it, i tried to check it process.server, this, context but unable to get the request object, i just want to get the full domain only, so how can I do that?

1 Answers

You can only get the hostname in the Browser JavaScript not internally in running nuxt app. As for nuxt app, it is running locally on the server (for example http://localhost:8080).

The information regarding hostname is present in services like Nginx/Apache.

Solution (One of them):

Use @nuxt/dotenv and store hostname in the environment variables:

hostname=example.com

then use wherever you want in your nuxt application with process.env.hostname

Related