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