add CORS headers
This commit is contained in:
10
server.py
10
server.py
@@ -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):
|
||||||
|
|||||||
Reference in New Issue
Block a user