add CORS headers

This commit is contained in:
cc
2025-02-28 11:27:18 +01:00
parent fec0228ee7
commit edd41a4005

View File

@@ -1,6 +1,6 @@
import csv, random import csv, random
from bottle import route, run from bottle import route, run, response
""" """
@@ -24,6 +24,10 @@ def question():
dict return value is automatically converted to JSON. dict return value is automatically converted to JSON.
""" """
response.set_header('Access-Control-Allow-Origin', '*')
response.set_header('Access-Control-Allow-Methods', 'GET,POST')
response.set_header('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin,Content-Type'
num_q = len(questions) num_q = len(questions)
rand_id = random.randint(1, num_q) rand_id = random.randint(1, num_q)
# id vs. index # id vs. index
@@ -37,6 +41,10 @@ def question():
@route('/question/<id:int>') @route('/question/<id:int>')
def question(id): def question(id):
response.set_header('Access-Control-Allow-Origin', '*')
response.set_header('Access-Control-Allow-Methods', 'GET,POST')
response.set_header('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin,Content-Type'
question = questions[id-1] question = questions[id-1]
q_with_headers = {} q_with_headers = {}
for k, v in zip(header, question): for k, v in zip(header, question):