CORS test
This commit is contained in:
parent
3a247d6ce1
commit
bd7807b42e
2
app.py
2
app.py
|
@ -1,4 +1,5 @@
|
|||
from flask import Flask
|
||||
from flask_cors import CORS
|
||||
from flask_restful import Api
|
||||
|
||||
from modules.KF3.database import Database as KF3DB
|
||||
|
@ -6,6 +7,7 @@ from modules.Kingdom.database import Database as KFKDB
|
|||
from modules.Archive.database import Database as KFADB
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app, support_credentials=True)
|
||||
app.config['JSON_AS_ASCII'] = False
|
||||
app.databases = {}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
import json
|
||||
from flask_cors import cross_origin
|
||||
from flask_restful import Resource
|
||||
from flask import current_app as app, jsonify, request
|
||||
from typing import TYPE_CHECKING
|
||||
|
@ -8,11 +9,12 @@ if TYPE_CHECKING:
|
|||
from modules.Archive.database import Database
|
||||
|
||||
class Archive_SetAction(Resource):
|
||||
@cross_origin(supports_credentials=True)
|
||||
def post(self):
|
||||
data = request.json
|
||||
data = request.get_json()
|
||||
|
||||
try:
|
||||
bypass = "allow_override" in data and data["allow_override"]
|
||||
bypass = ("allow_override" in data) and data["allow_override"]
|
||||
action = data["action_taken"]
|
||||
if "id_str" in data:
|
||||
id = int(data["id_str"])
|
||||
|
@ -23,6 +25,8 @@ class Archive_SetAction(Resource):
|
|||
except Exception as e:
|
||||
print(e)
|
||||
response = app.response_class(response=e, status=400)
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
|
||||
db : Database = app.databases["Archive"]
|
||||
query = f"UPDATE x_posts SET action_taken = {action} WHERE id = {id}"
|
||||
|
@ -34,7 +38,7 @@ class Archive_SetAction(Resource):
|
|||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
mimetype='text/plain'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
|
|
Loading…
Reference in New Issue