Allow CORS from other zunes.tk domains and 127.0.0.X for testing

This commit is contained in:
Yoshi Askharoun
2021-05-25 13:11:24 -05:00
parent 886aa46def
commit 2e77cfdaf8
+16 -1
View File
@@ -1,4 +1,3 @@
from urllib.error import HTTPError
from xml.dom.minidom import Document, Element
from flask import Flask, request, abort, Response
@@ -15,6 +14,22 @@ app = Flask(__name__)
musicbrainzngs.set_useragent("Zune", "4.8", "https://github.com/yoshiask/PyZuneCatalogServer")
import re
@app.after_request
def allow_zunestk_cors(response):
r: str = request.host_url
print(r)
if re.match(r"https?://(127\.0\.0\.(?:\d*)|(?:\w*\.)*zunes\.tk)", r):
response.headers.add('Access-Control-Allow-Origin', r)
response.headers.add('Access-Control-Allow-Credentials', 'true')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type')
response.headers.add('Access-Control-Allow-Headers', 'Cache-Control')
response.headers.add('Access-Control-Allow-Headers', 'X-Requested-With')
response.headers.add('Access-Control-Allow-Headers', 'Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE')
return response
@app.route(f"/v3.2/<string:locale>/hubs/music")
def hubs_music(locale: str):
with open('reference/catalog.zune.net_v3.2_{locale}_hubs_music.xml', 'r') as file: