I'm doing a school project on Ionic and I've decided to create a basic API for my initial needs. I'm using Flask since it's quite simple, but I've hit a wall (after setting up everything and hosting on Heroku) when it comes to the GET request. This is the API code (I'm using mock files instead of a database for now, is it the source of my issues?):
import os
from flask import Flask, send_from_directory
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
@app.route('/')
def hello():
return 'API do SIGNCLASS'
@app.route('/files/<path:file>')
@cross_origin()
def sendfile(file):
return send_from_directory('files', file)
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
And this is the request code (it's Angular by the way)
public getCourse(courseId): Observable<Level[]> {
const url = `${this.contentUrl}course${courseId}.json`;
return this.http.get<Level[]>(url)
.pipe(
catchError(this.handleError('Obter níveis', []))
);
}
As you can see I've already set up flask_cors but it's no good, I'm still getting this:
Failed to load https://apiurlishere: No
'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8100' is therefore not allowed access.
EDIT: I've checked it with Postman and there I can find:
access-control-allow-origin →*
So I'm truly lost.