Permalink
Browse files

added cors support and more tests

  • Loading branch information...
1 parent b03a40b commit 9c2b411803185a2233f3eb11af395c1b62a6651b @tarekziade tarekziade committed Feb 12, 2013
Showing with 26 additions and 12 deletions.
  1. +1 −0 monolith.ini
  2. +5 −0 monolith/__init__.py
  3. +3 −6 monolith/media/lib/monolith.js
  4. +5 −4 monolith/tests/monolith.ini
  5. +8 −0 monolith/tests/test_monolith.js
  6. +4 −2 monolith/views.py
View
@@ -1,6 +1,7 @@
[app:main]
use = egg:monolith
elasticsearch.hosts = localhost:9200
+cors.origins = *
[server:main]
use = egg:waitress#main
View
@@ -33,6 +33,11 @@ def date_adapter(obj, request):
settings = config.registry.settings
host = settings.get('elasticsearch.host', 'http://localhost:9200')
+
+ # XXX we need a way to lazy-inject this to the cornice views
+ cors_origins = settings.get('cors.origins', '*')
+ cors_origins = cors_origins.split(',')
+
config.registry.es = ElasticSearch(host)
config.add_subscriber(attach_elasticsearch, NewRequest)
return config.make_wsgi_app()
@@ -32,7 +32,6 @@ Highcharts.setOptions({
});
-jQuery.support.cors = true;
function queryES(server, query) {
var result;
@@ -43,8 +42,6 @@ function queryES(server, query) {
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: false,
- dataType: "json",
- //crossDomain: true,
data: query,
async: false,
success: function(json) { result = json;},
@@ -116,12 +113,13 @@ $.Class.extend("MonolithBase", {},
$.ajax({url: this.server,
type: 'GET',
async: false,
+ dataType: "json",
success: function(result) { info = result; },
error: function (xhr, textStatus, errorThrown) {
- alert("error " + textStatus + " " + xhr.responseText);
+ console.log(xhr.responseText);
},
failure: function(errMsg) {
- alert("failure " + errMsg);
+ console.log("failure " + errMsg);
}
});
return info;
@@ -136,7 +134,6 @@ $.Class.extend("MonolithBase", {},
type: "POST",
url: this.es_server,
contentType: "application/json; charset=utf-8",
- dataType: "json",
processData: false,
dataType: "json",
data: query,
@@ -1,6 +1,7 @@
[app:main]
use = egg:monolith
elasticsearch.hosts = localhost:9998
+cors.origins = *
[server:main]
use = egg:waitress#main
@@ -19,18 +20,18 @@ keys = console
keys = generic
[logger_root]
-level = INFO
+level = DEBUG
handlers = console
[logger_monolith]
-level = INFO
-handlers =
+level = DEBUG
+handlers = console
qualname = monolith
[handler_console]
class = StreamHandler
args = (sys.stderr,)
-level = INFO
+level = DEBUG
formatter = generic
[formatter_generic]
@@ -18,6 +18,14 @@ describe("Utils suite", function() {
expect(result).toEqual(wanted);
});
+ it("'getInfo'", function() {
+
+ var chart = new MonolithBase("http://0.0.0.0:9997", "", "", "", "", "");
+ var wanted = [ 'downloads_count', 'users_count' ];
+ expect(chart.info.fields).toEqual(wanted);
+ });
+
+
});
View
@@ -12,7 +12,8 @@ class ElasticSearchQuery(MappingSchema):
names = SchemaNode(Seq(), location='body')
-info = Service(name='info', path='/')
+info = Service(name='info', path='/',
+ cors_policy={'origins': ('*',), 'credentials': True})
@info.get(renderer='json')
@@ -26,7 +27,8 @@ def get_info(request):
es_time = Service(
name='elasticsearch-time',
path='/v1/time',
- description="Raw access to ES time-series data.")
+ description="Raw access to ES time-series data.",
+ cors_policy={'origins': ('*',), 'credentials': True})
es_totals = Service(

0 comments on commit 9c2b411

Please sign in to comment.