Jul-01-2023, 01:08 AM
(This post was last modified: Jul-01-2023, 01:08 AM by michaelnicol.)
Hello,
I am attempting to work on a backend server for a front end that will compute data.
To test this, I want to forward between ports. On the front end, I have the following code:
And On the backend, I used an example flask server:
POST http://localhost:5000/ net::ERR_ABORTED 405 (METHOD NOT ALLOWED)
I am attempting to work on a backend server for a front end that will compute data.
To test this, I want to forward between ports. On the front end, I have the following code:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Cross-Origin-Resource-Policy", "*")
var raw = JSON.stringify({
dataType: "stl"
});
console.log(raw)
var requestOptions = {
method: "POST",
headers: myHeaders,
mode: "cors",
body: raw,
redirect: "follow"
};
fetch("http://localhost:5000/", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error));[/python]And On the backend, I used an example flask server:
from flask import Flask, request
from urllib.request import urlopen
app = Flask(__name__)
@app.route('/', methods=['POST'])
def convert():
print("Received Request")
print(request.json())
return "Success"
if __name__ == "__main__":
app.run(debug=True)However, I receive the following error on the fetch:Access to fetch at 'http://localhost:5000/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.And If I put it on no-cors:
POST http://localhost:5000/ net::ERR_ABORTED 405 (METHOD NOT ALLOWED)
