Skip to content

Flask cors issue #393

@SinghAbhinav04

Description

@SinghAbhinav04

Hey guys , I have been stuck over this Cors issue in Flask .. basically I have hosted my Flask backend on Railway and I am trying to Access via my localhost and all I get is =>

Error:
Access to fetch at 'https://test.up.railway.app/auth/login' from origin 'http://127.0.0.1:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.Understand this error

Please find my script below :

from dotenv import load_dotenv
load_dotenv()
from flask import Flask
from flask_cors import CORS
import os
import sys

app = Flask(name)

CORS(app)
@app.before_request
def before_request():
headers = {'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'}
if request.method.lower() == 'options':
return jsonify(headers), 200

@app.route("/", methods=["GET"])
def get_hey():
print("Root endpoint hit!")
return "hey from Koma", 200

try:
from routes.auth import auth_bp
app.register_blueprint(auth_bp, url_prefix="/auth")
except Exception as e:
print(f"Failed to import auth blueprint: {e}")

try:
from routes.manga import manga_bp
app.register_blueprint(manga_bp, url_prefix="/koma")
except Exception as e:
print(f"Failed to import manga blueprint: {e}")

if name == "main":
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))

Thank You ..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions