Remove `/version` endpoint and bootstrapFonts at process startup (now done in windshaft)

remotes/origin/node-12
Daniel García Aubert 5 years ago
parent 44970b78a1
commit c25678cc28

@ -5,10 +5,9 @@ var HealthCheck = require('./monitoring/health-check');
var WELCOME_MSG = 'This is the CartoDB Maps API, ' + var WELCOME_MSG = 'This is the CartoDB Maps API, ' +
'see the documentation at http://docs.cartodb.com/cartodb-platform/maps-api.html'; 'see the documentation at http://docs.cartodb.com/cartodb-platform/maps-api.html';
function ServerInfoController (versions) { function ServerInfoController () {
this.healthConfig = global.environment.health || {}; this.healthConfig = global.environment.health || {};
this.healthCheck = new HealthCheck(global.environment.disabled_file); this.healthCheck = new HealthCheck(global.environment.disabled_file);
this.versions = versions || {};
} }
module.exports = ServerInfoController; module.exports = ServerInfoController;
@ -16,7 +15,6 @@ module.exports = ServerInfoController;
ServerInfoController.prototype.route = function (monitorRouter) { ServerInfoController.prototype.route = function (monitorRouter) {
monitorRouter.get('/health', this.health.bind(this)); monitorRouter.get('/health', this.health.bind(this));
monitorRouter.get('/', this.welcome.bind(this)); monitorRouter.get('/', this.welcome.bind(this));
monitorRouter.get('/version', this.version.bind(this));
}; };
ServerInfoController.prototype.welcome = function (req, res) { ServerInfoController.prototype.welcome = function (req, res) {

@ -21,10 +21,6 @@ module.exports = function createServer (serverOptions) {
// Make stats client globally accessible // Make stats client globally accessible
global.statsClient = StatsClient.getInstance(serverOptions.statsd); global.statsClient = StatsClient.getInstance(serverOptions.statsd);
serverOptions.grainstore.mapnik_version = mapnikVersion(serverOptions);
bootstrapFonts(serverOptions);
const app = express(); const app = express();
app.enable('jsonp callback'); app.enable('jsonp callback');
@ -41,63 +37,8 @@ module.exports = function createServer (serverOptions) {
apiRouter.route(app, serverOptions.routes.api); apiRouter.route(app, serverOptions.routes.api);
const versions = getAndValidateVersions(serverOptions); const serverInfoController = new ServerInfoController();
const serverInfoController = new ServerInfoController(versions);
serverInfoController.route(app); serverInfoController.route(app);
return app; return app;
}; };
function bootstrapFonts (opts) {
// Set carto renderer configuration for MMLStore
opts.grainstore.carto_env = opts.grainstore.carto_env || {};
var cenv = opts.grainstore.carto_env;
cenv.validation_data = cenv.validation_data || {};
if (!cenv.validation_data.fonts) {
mapnik.register_system_fonts();
mapnik.register_default_fonts();
cenv.validation_data.fonts = _.keys(mapnik.fontFiles());
}
}
function mapnikVersion (opts) {
return opts.grainstore.mapnik_version || mapnik.versions.mapnik;
}
function getAndValidateVersions (options) {
var warn = console.warn.bind(console); // jshint ignore:line
var packageDefinition = require('../package.json');
var declaredDependencies = packageDefinition.dependencies || {};
var installedDependenciesVersions = {
camshaft: require('camshaft').version,
grainstore: windshaft.grainstore.version(),
mapnik: windshaft.mapnik.versions.mapnik,
node_mapnik: windshaft.mapnik.version,
'turbo-carto': require('turbo-carto').version,
windshaft: windshaft.version,
windshaft_cartodb: packageDefinition.version
};
if (process.env.NODE_ENV !== 'test') {
var dependenciesToValidate = ['camshaft', 'turbo-carto', 'windshaft'];
dependenciesToValidate.forEach(function (depName) {
var declaredDependencyVersion = declaredDependencies[depName];
var installedDependencyVersion = installedDependenciesVersions[depName];
if (!semver.satisfies(installedDependencyVersion, declaredDependencyVersion)) {
warn(`Dependency="${depName}" installed version="${installedDependencyVersion}" does ` +
`not match declared version="${declaredDependencyVersion}". Check your installation.`);
}
});
// Be nice and warn if configured mapnik version is != installed mapnik version
if (windshaft.mapnik.versions.mapnik !== options.grainstore.mapnik_version) {
warn('WARNING: detected mapnik version (' + windshaft.mapnik.versions.mapnik + ')' +
' != configured mapnik version (' + options.grainstore.mapnik_version + ')');
}
}
return installedDependenciesVersions;
}

@ -302,15 +302,6 @@ describe('get requests with cache headers', function () {
); );
}); });
it('/version', function (done) {
assert.response(
server,
getRequest('/version'),
statusOkResponse,
noCacheHeaders(done)
);
});
it('/health', function (done) { it('/health', function (done) {
assert.response( assert.response(
server, server,

@ -35,29 +35,6 @@ describe('server', function () {
}, function () { done(); }); }, function () { done(); });
}); });
/// /////////////////////////////////////////////////////////////////
//
// GET VERSION
//
/// /////////////////////////////////////////////////////////////////
it('get /version returns versions', function (done) {
assert.response(server, {
url: '/version',
method: 'GET'
}, {
status: 200
}, function (res) {
var parsed = JSON.parse(res.body);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft'), "No 'windshaft' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'grainstore'), "No 'grainstore' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'node_mapnik'), "No 'node_mapnik' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'mapnik'), "No 'mapnik' version in " + parsed);
// TODO: check actual versions ?
done();
});
});
/// ///////////////////////////////////////////////////////////////// /// /////////////////////////////////////////////////////////////////
// //
// GET GRID // GET GRID

@ -39,23 +39,6 @@ describe('server', function () {
} }
); );
}); });
it('get call to server returns 200', function (done) {
assert.response(server, {
url: '/version',
method: 'GET'
}, {
status: 200
}, function (res) {
var parsed = JSON.parse(res.body);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft_cartodb'), "No 'windshaft_cartodb' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft'), "No 'windshaft' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'grainstore'), "No 'grainstore' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'node_mapnik'), "No 'node_mapnik' version in " + parsed);
assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'mapnik'), "No 'mapnik' version in " + parsed);
done();
});
});
}); });
describe('server old_api', function () { describe('server old_api', function () {

Loading…
Cancel
Save