I want to divide my vuejs frontend project into two parts as development and test. In the development part, I want to work in my local and request the example:8010 urline, and in the test part, I want to send a request to the example:80 address. How can I do this, I did a source search but couldn't find anything.
Example of a request I wrote:
var formData = new FormData();
formData.append('file', this.image[0]);
await axios
.post('example', formData, {
headers: {
Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6fdsaeqImNoZ3VuYXkzQGdtYWlsLmNvbqSIsImlkIjoxLCJ0eXBlIjoxLCJpYXQiOjE2NDU0NDUxMjR9.Kg8NcFiAKtBHxkQsRwl2pO6svp7SDQSQw13SJ4xe1vc`,
},
})
.then((response) => {
console.log(response.data.id);
})
.catch((error) => {
console.log(error);
});
Serkan
You can use .env files for your environments. You can add dotenv package your project, or you can give parameters inside of your scripts part of you package.json
here you can follow this page to use your env variables inside vue app. Keep in mind you must start VUE_APP for your variables:
VUE_APP_BASE_API = 'yourapplink/api'
You should create 2 .env files 1 for your local development other for your production and you can add as much as you like.
You can create .env.development and put your variables in it then start your vue app with:
vue-cli-service build --mode development
And you should see app using your .env.development file.