Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

somenet77's avatar

How to set api end point for local development and production?

import axios from 'axios'

const Api = axios.create({
    baseURL: 'http://127.0.0.1/api/v1'
})

export default Api

This is set up to call the API endpoint. which work fine in local development. But I want to change this URL to match my production domain URL while building assets.

npm run production

While running the above command I get a local development path. I want to set that baseURL into the production server url.

How can I get this for laravel 8 and vue 3?

0 likes
1 reply
srasch's avatar
srasch
Best Answer
Level 14

Why don't you make it "dynamically" by doing something like this?

import axios from 'axios'

const Api = axios.create({
    baseURL: window.location.protocol + '//' + window.location.hostname  + '/api/v1'
})

export default Api
2 likes

Please or to participate in this conversation.