Hi,
When I deploy my project into the production environment, it is working fine when I use this URL
var boa_report = {
"dataSource":
{
Type: "api",
index: "boa-index",
url: "https://XXXXX.azurewebsites.net/api/api"
},
When I go back to my project locally, I need to change back the URL to this in order to make it work:
url: "http://localhost:51718/api"
Is there a way that it could change it automatically depending if it is running on my machine or in azure bu putting the URL in a variable or... ?
Thank you for your response and ideas.
Hello, Laurier!
Thank you for contacting us.
We want to suggest you two possible ways to determine URL automatically:
1.Use window.location
to get the current URL and put it into variable as follows:
isLocal = window.location.href.includes('localhost')
|| window.location.href.includes('127.0.0.1')
url=isLocal ? 'http://localhost:51718/api'
: 'https://XXXXX.azurewebsites.net/api/api'
var boa_report = {
“dataSource”:
{
Type: “api”,
index: “boa-index”,
url: url
},
...
}
2. Send GET
request, e.x. via ajax, to the 'http://localhost:51718/api/fieldname' and check the response. Then, determine the api
variable depending on the returned data in the same way as in the previous example.
Hope it helps. Feel free to ask if any further questions arise.
Regards,
Solomiia
Thank you for the suggestions Solomiia,
I will try those.
Regards
Hello, Laurier!
Thank you for your response.
We will be glad to hear your feedback on the proposed approaches.
You are welcome to ask if any further questions arise.
Best regards,
Solomiia