Combined cors and cors_origin config options into one

This commit is contained in:
Andre Miller 2015-01-20 19:53:04 +02:00
parent 47ea4b7d8b
commit f815138758

View file

@ -23,8 +23,8 @@ from werkzeug.routing import BaseConverter, PathConverter
import os
import json
# Utilities.
# Utilities.
def _rep(obj, expand=False):
"""Get a flat -- i.e., JSON-ish -- representation of a beets Item or
@ -256,8 +256,7 @@ class WebPlugin(BeetsPlugin):
self.config.add({
'host': u'127.0.0.1',
'port': 8337,
'cors': False,
'cors_origin': '*',
'cors': '',
})
def commands(self):
@ -273,15 +272,16 @@ class WebPlugin(BeetsPlugin):
self.config['port'] = int(args.pop(0))
app.config['lib'] = lib
# Enable CORS if required
# Enable CORS if required.
if self.config['cors']:
print "Enabling cors"
from flask.ext.cors import CORS
app.config['CORS_ALLOW_HEADERS'] = "Content-Type"
app.config['CORS_RESOURCES'] = {
r"/*": {"origins": self.config['cors_origin'].get(str)}
r"/*": {"origins": self.config['cors'].get(str)}
}
CORS(app)
# Start the web application.
app.run(host=self.config['host'].get(unicode),
port=self.config['port'].get(int),
debug=opts.debug, threaded=True)