diff --git a/requirements.txt b/requirements.txt index 9687a04..b2dcca1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ flask flask-restful +flask-cors diff --git a/server/api.py b/server/api.py index 1076e42..962dc08 100644 --- a/server/api.py +++ b/server/api.py @@ -58,7 +58,7 @@ class Question(Resource): args = parser.parse_args() # Generate new Question ID - q_id = Nonewt + q_id = None while q_id in active_questions.keys() or q_id is None: q_id = generate_id(5) @@ -78,7 +78,7 @@ class Question(Resource): question = copy.copy(active_questions[q_id]) del question['answer'] - return 201, question + return question, 201 def delete(self, question_id): """Delete a question object from the running before it is automatically removed.""" diff --git a/server/arithmetic.py b/server/arithmetic.py index 60d43c4..9536f48 100644 --- a/server/arithmetic.py +++ b/server/arithmetic.py @@ -58,7 +58,7 @@ def simplify_fraction(): return { 'type': inspect.stack()[0][3], - 'question': f'Simplify. \\frac{{{c}}}{{{d}}}', + 'question': f'\\frac{{{c}}}{{{d}}}', 'answer': f'{a}/{b}' } diff --git a/server/create_app.py b/server/create_app.py index cb39263..bf53e97 100644 --- a/server/create_app.py +++ b/server/create_app.py @@ -6,6 +6,7 @@ The main app creation, registering extensions, API routes, the Vue.js catch all from flask import Flask, render_template, jsonify from flask_restful import Api +from flask_cors import CORS from server import exceptions from server.api import Question, Questions, Category, Categories @@ -19,6 +20,9 @@ def create_app(env=None): template_folder="./../dist" ) + # Add CORS support + cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) + # Instantiate Flask-Restful API and register appropriate routes api = Api(app, prefix='/api/') api.add_resource(Question, '/question/', '/question/') diff --git a/server/exceptions.py b/server/exceptions.py index ee8ccbd..cdb3db2 100644 --- a/server/exceptions.py +++ b/server/exceptions.py @@ -5,6 +5,7 @@ Stores all API exceptions neatly for importing and usage elsewhere. """ from typing import Tuple + # TODO: Improve exception management to cut down needless class definitions. # TODO: Add 'extra' message parameter to base APIException kwargs. @@ -75,7 +76,6 @@ class InvalidURIParam(APIException): return error - class InvalidQuestion(InvalidURIParam): MESSAGE = "A invalid question was specified in the request URI and could not be resolved."