'My server keeps responded with error 404 forbidden. Can anyone see what I am doing wrong here?
My server was working earlier, but now it continuously responds as error 404 and I cannot figure out why. Apparently there is a mistake on my side but I cannot work out what it is.
`var locationLat = ''; var locationLng = '';
var destinationLat = ''; var destinationLng = '';
var quote = 0;
function getQuotes() {
var location = document.getElementById('location').value;
var destination = document.getElementById('destination').value;
fetch(`https://maps.googleapis.com/maps/api/geocode/json?address=${location}&key=AIzaSyDpZkgmNpUUE_AfU7-3WM-ExBSH7yb39AI`)
.then(response => response.json())
.then(response => {
locationLat = response.results[0].geometry.location.lat;
locationLng = response.results[0].geometry.location.lng;
}).catch(error => {document.getElementById('quote').innerHTML = "An error has occured" ,console.log(error)})
fetch(`https://ampthilcabs.herokuapp.com/https://maps.googleapis.com/maps/api/geocode/json?address=${destination}&key=AIzaSyDpZkgmNpUUE_AfU7-3WM-ExBSH7yb39AI`, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
})
.then(response => response.json())
.then(response => {
destinationLat = response.results[0].geometry.location.lat;
destinationLng = response.results[0].geometry.location.lng;
}).catch(error => {document.getElementById('quote').innerHTML = "An error has occured" ,console.log(error)})
fetch(`https://ampthilcabs.herokuapp.com/https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=${locationLat},${locationLng}&destinations=${destinationLat},${destinationLng}&key=AIzaSyDpZkgmNpUUE_AfU7-3WM-ExBSH7yb39AI`,
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(response => {
const miles = parseInt(response.rows[0].elements[0].distance.text);
const price = miles * 2;
document.getElementById('miles').innerHTML = miles
document.getElementById('quote').innerHTML = price;
var value = document.querySelector('#timings').value;
document.getElementById('quoteContainer').style.display = 'flex';
if (document.getElementById('numberOfPeople').value == 5) {
var percentage = price * 0.25;
price = price + percentage;
console.log("Number of people is 5");
document.getElementById('quote').innerHTML = price;
document.getElementById('miles').innerHTML = miles;
}
if (value == 'premium') {
var percentage = price * 0.25;
price = price + percentage;
console.log('Value is premium');
document.getElementById('quote').innerHTML = price;
document.getElementById('miles').innerHTML = miles;
}
var date = new Date(document.getElementById('date').value);
if (date.getDay() == 0) {
var percentage = price * 0.5;
price = price + percentage;
console.log(date.getDay());
document.getElementById('quote').innerHTML = price;
document.getElementById('miles').innerHTML = miles;
}
console.log(date.getDay());
}).catch(error => {document.getElementById('quote').innerHTML = "An error has occured" ,console.log(error)})
}`
- Remove server whitelisting -Changing the server
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
