#How to programitically get the baseURL that nuxt is running on?

19 messages · Page 1 of 1 (latest)

bright birch
#

Hi there, I want to programatically know what baseURL nuxt is running on for a module.

any guidance to how that works?

ie in development if someone runs it at http://localhost:3210 is there a way to know that inside a nuxt module?

rigid nebula
#

Does that module run on the client only? Otherwise I think this is going to be pretty hard. Maybe you have to define an option for the module users to put in the baseUrl in the config.

minor frigate
#

nuxt.options.devServer.url

rigid nebula
minor frigate
#

I thought the question was about dev. "ie in development if someone runs" . . .

#

on prod I guess you could check env vars.

rigid nebula
bright birch
#

my apologies dev was the orginal issue but i would need if for prod as well

#

in script setup how do you get the nuxt variable?

#

just knowing some options can be enough for me to test, i will try the devserver url for the server side and for the client side i can probably just use some sort of browser code for it

minor frigate
#

Just one way . . .

#

One way is to set the PORT and HOST in the .env

#

if you do that, you can access the value like so:

#

But I'd imagine you'd have the app behind a proxy

#

so I'm not sure if this method would be helpful on PROD.

rigid nebula
#

I think it's the best here to provide a config where users of the module could put their own env variable in. (in nuxt.config).

#

Since for example you don't have a access to env vars without the NUXT_ prefix if you deploy to lets say vercel