I use to make a fetch request from localhost. The javascript for that was inside a script tag inside the index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
...
<script type="text/javascript">
...
var config = {}
for (var file in guis) config[file] = guis[file].getValue()
fetch('/one/two/three', {method: 'POST', body: JSON.stringify({type: type, config: config }) })
.then(response => response.json())
.then(function(test) {
if ('href' in test) {
setCookie("test_str", test['href'].split('http:',2)[1])
SomeFuction();
JumpTo();
} else {
var alert_message = `Can't run test. ${test.detail}`;
window.alert(alert_message);
JumpTo();
}
})
.catch(function (err) {
var alert_message = `Can't run test: ${err}`;
window.alert(alert_message);
})
...
</script>
</body>
</html>
and it worked. But after a while I moved all the javascript (~800 lines), to an external file and I imported it like usually:
<script src="./index.js"></script>
and after that I started getting
POST http://172.17.0.2/one/two/three 400 (Bad Request)
How do I fix this error?