Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added serverMetadata option for layer group, close #182 CDB-1940

  • Loading branch information...
commit 5bfc3608560551fa2f127163e08067f18fe76b16 1 parent 7eb26a7
@javisantana javisantana authored
View
1  NEWS.md
@@ -12,6 +12,7 @@ Enhancements:
- Add "cacheDns" statsd setting in the example configs
- Do not send duplicated stats on template instanciation
- Do not die on dns resolution errors (#178, #180)
+ - Allow to set server related configuration in serverMetadata (#182)
Bug fixes:
View
6 config/environments/production.js.example
@@ -116,6 +116,12 @@ var config = {
// X-Tiler-Profile header containing elapsed timing for various
// steps taken for producing the response.
,useProfiler:false
+ ,serverMetadata: {
+ cdn_url: {
+ http: 'api.cartocdn.com',
+ https: 'cartocdn.global.ssl.fastly.net'
+ }
+ }
};
module.exports = config;
View
6 config/environments/staging.js.example
@@ -116,6 +116,12 @@ var config = {
// X-Tiler-Profile header containing elapsed timing for various
// steps taken for producing the response.
,useProfiler:true
+ ,serverMetadata: {
+ cdn_url: {
+ http: 'api.cartocdn.com',
+ https: 'cartocdn.global.ssl.fastly.net'
+ }
+ }
};
module.exports = config;
View
8 lib/cartodb/server_options.js
@@ -375,6 +375,14 @@ module.exports = function(){
}
}
+ // include in layergroup response the variables in serverMedata
+ // those variables are useful to send to the client information
+ // about how to reach this server or information about it
+ var serverMetadata = global.environment.serverMetadata;
+ if (serverMetadata) {
+ _.extend(response, serverMetadata);
+ }
+
// Don't wait for the mapview count increment to
// take place before proceeding. Error will be logged
// asyncronously
View
34 test/acceptance/multilayer.js
@@ -192,6 +192,40 @@ suite('multilayer', function() {
);
});
+
+ test("should include serverMedata in the response", function(done) {
+ global.environment.serverMetadata = { cdn_url : { http:'test', https: 'tests' } }
+ var layergroup = {
+ version: '1.0.0',
+ layers: [
+ { options: {
+ sql: 'select cartodb_id, ST_Translate(the_geom_webmercator, 5e6, 0) as the_geom_webmercator from test_table limit 2',
+ cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
+ cartocss_version: '2.0.1'
+ } }
+ ]
+ };
+
+ var expected_token;
+ Step(
+ function do_create_get()
+ {
+ var next = this;
+ assert.response(server, {
+ url: '/tiles/layergroup?config=' + encodeURIComponent(JSON.stringify(layergroup)),
+ method: 'GET',
+ headers: {host: 'localhost'}
+ }, {}, function(res, err) { next(err, res); });
+ },
+ function do_check_create(err, res) {
+ var parsed = JSON.parse(res.body);
+ assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
+ done();
+ }
+ )
+ });
+
+
// See https://github.com/CartoDB/Windshaft-cartodb/issues/176
// NOTE: another test like this is in templates.js
test("get creation requests no cache", function(done) {
View
46 test/acceptance/templates.js
@@ -308,6 +308,52 @@ suite('template_api', function() {
});
});
+ test("instance endpoint should return server metadata", function(done){
+ global.environment.serverMetadata = { cdn_url : { http:'test', https: 'tests' } }
+ var tmpl = _.clone(template_acceptance1)
+ tmpl.name = "rambotemplate2"
+
+ Step(function postTemplate1(err, res) {
+ var next = this;
+ var post_request = {
+ url: '/tiles/template?api_key=1234',
+ method: 'POST',
+ headers: {host: 'localhost', 'Content-Type': 'application/json' },
+ data: JSON.stringify(tmpl)
+ };
+ assert.response(server, post_request, {}, function(res) {
+ next(null, res);
+ });
+ },
+ function testCORS() {
+ var next = this;
+ assert.response(server, {
+ url: '/tiles/template/' + tmpl.name,
+ method: 'POST',
+ headers: {host: 'localhost', 'Content-Type': 'application/json' },
+ },{
+ status: 200
+ }, function(res) {
+ var parsed = JSON.parse(res.body);
+ assert.ok(_.isEqual(parsed.cdn_url, global.environment.serverMetadata.cdn_url));
+ next(null);
+ });
+ },
+ function deleteTemplate(err) {
+ if ( err ) throw err;
+ var del_request = {
+ url: '/tiles/template/' + tmpl.name + '?api_key=1234',
+ method: 'DELETE',
+ headers: {host: 'localhost', 'Content-Type': 'application/json' }
+ }
+ var next = this;
+ assert.response(server, del_request, {},
+ function(res) { done(); });
+ }
+ );
+ });
+
+
test("can list templates", function(done) {
Please sign in to comment.
Something went wrong with that request. Please try again.