[MediaWiki-commits] [Gerrit] maps...package[master]: initial commit
Gehel has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/395478 ) Change subject: initial commit .. initial commit Change-Id: Iffebc2da34e0a1c64a02d12a5cf0a0a0f1216c61 --- A .dockerignore A .gitignore A .gitreview A app.js A config.dev.yaml A package.json A server.js A targets.yaml 8 files changed, 412 insertions(+), 0 deletions(-) Approvals: Gehel: Verified; Looks good to me, approved diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000..563df11 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +coverage +node_modules diff --git a/.gitignore b/.gitignore new file mode 100644 index 000..a0a1c47 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +Dockerfile +.idea/ +coverage +config.yaml +node_modules +npm-debug.log +vectors +variables.yaml diff --git a/.gitreview b/.gitreview new file mode 100644 index 000..fd59be6 --- /dev/null +++ b/.gitreview @@ -0,0 +1,6 @@ +[gerrit] +host=gerrit.wikimedia.org +port=29418 +project=maps/tilerator/package.git +defaultbranch=master +defaultrebase=0 diff --git a/app.js b/app.js new file mode 100644 index 000..f866804 --- /dev/null +++ b/app.js @@ -0,0 +1,203 @@ +'use strict'; + + +var http = require('http'); +var BBPromise = require('bluebird'); +var express = require('express'); +var compression = require('compression'); +var bodyParser = require('body-parser'); +var fs = BBPromise.promisifyAll(require('fs')); +var sUtil = require('./lib/util'); +var packageInfo = require('./package.json'); +var yaml = require('js-yaml'); + + +/** + * Creates an express app and initialises it + * @param {Object} options the options to initialise the app with + * @return {bluebird} the promise resolving to the app object + */ +function initApp(options) { + +// the main application object +var app = express(); + +// get the options and make them available in the app +app.logger = options.logger;// the logging device +app.metrics = options.metrics; // the metrics +app.conf = options.config; // this app's config options +app.info = packageInfo; // this app's package info + +// ensure some sane defaults +if(!app.conf.port) { app.conf.port = ; } +if(!app.conf.interface) { app.conf.interface = '0.0.0.0'; } +if(app.conf.compression_level === undefined) { app.conf.compression_level = 3; } +if(app.conf.cors === undefined) { app.conf.cors = '*'; } +if(app.conf.csp === undefined) { +app.conf.csp = +"default-src 'self'; object-src 'none'; media-src *; img-src *; style-src *; frame-ancestors 'self'"; +} + +// set outgoing proxy +if(app.conf.proxy) { +process.env.HTTP_PROXY = app.conf.proxy; +// if there is a list of domains which should +// not be proxied, set it +if(app.conf.no_proxy_list) { +if(Array.isArray(app.conf.no_proxy_list)) { +process.env.NO_PROXY = app.conf.no_proxy_list.join(','); +} else { +process.env.NO_PROXY = app.conf.no_proxy_list; +} +} +} + +// set up header whitelisting for logging +if(!app.conf.log_header_whitelist) { +app.conf.log_header_whitelist = [ +'cache-control', 'content-type', 'content-length', 'if-match', +'user-agent', 'x-request-id' +]; +} +app.conf.log_header_whitelist = new RegExp('^(?:' + app.conf.log_header_whitelist.map(function(item) { +return item.trim(); +}).join('|') + ')$', 'i'); + +// set up the spec +if(!app.conf.spec) { +app.conf.spec = __dirname + '/spec.yaml'; +} +if(app.conf.spec.constructor !== Object) { +try { +app.conf.spec = yaml.safeLoad(fs.readFileSync(app.conf.spec)); +} catch(e) { +app.logger.log('warn/spec', 'Could not load the spec: ' + e); +app.conf.spec = {}; +} +} +if(!app.conf.spec.swagger) { +app.conf.spec.swagger = '2.0'; +} +if(!app.conf.spec.info) { +app.conf.spec.info = { +version: app.info.version, +title: app.info.name, +description: app.info.description +}; +} +app.conf.spec.info.version = app.info.version; +if(!app.conf.spec.paths) { +app.conf.spec.paths = {}; +} + +// set the CORS and CSP headers +app.all('*', function(req, res, next) { +// +// Tilerator is an admin app, there is no point to set app.conf.cors and app.conf.csp +// +sUtil.initAndLogRequest(req, app); +next(); +}); + +// disable the X-Powered-By header +app.set('x-powered-by', false); +// disable the ETag header - users should provide them! +app.set('etag', false); +// enable compression +app.use(compression({level: app.conf.compression_level})); +// use the JSON body
[MediaWiki-commits] [Gerrit] maps...package[master]: initial commit
Gehel has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/395478 ) Change subject: initial commit .. initial commit Change-Id: Iffebc2da34e0a1c64a02d12a5cf0a0a0f1216c61 --- A .dockerignore A .gitignore A app.js A config.dev.yaml A package.json A server.js A targets.yaml 7 files changed, 406 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/maps/tilerator/package refs/changes/78/395478/1 diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000..563df11 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +coverage +node_modules diff --git a/.gitignore b/.gitignore new file mode 100644 index 000..a0a1c47 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +Dockerfile +.idea/ +coverage +config.yaml +node_modules +npm-debug.log +vectors +variables.yaml diff --git a/app.js b/app.js new file mode 100644 index 000..f866804 --- /dev/null +++ b/app.js @@ -0,0 +1,203 @@ +'use strict'; + + +var http = require('http'); +var BBPromise = require('bluebird'); +var express = require('express'); +var compression = require('compression'); +var bodyParser = require('body-parser'); +var fs = BBPromise.promisifyAll(require('fs')); +var sUtil = require('./lib/util'); +var packageInfo = require('./package.json'); +var yaml = require('js-yaml'); + + +/** + * Creates an express app and initialises it + * @param {Object} options the options to initialise the app with + * @return {bluebird} the promise resolving to the app object + */ +function initApp(options) { + +// the main application object +var app = express(); + +// get the options and make them available in the app +app.logger = options.logger;// the logging device +app.metrics = options.metrics; // the metrics +app.conf = options.config; // this app's config options +app.info = packageInfo; // this app's package info + +// ensure some sane defaults +if(!app.conf.port) { app.conf.port = ; } +if(!app.conf.interface) { app.conf.interface = '0.0.0.0'; } +if(app.conf.compression_level === undefined) { app.conf.compression_level = 3; } +if(app.conf.cors === undefined) { app.conf.cors = '*'; } +if(app.conf.csp === undefined) { +app.conf.csp = +"default-src 'self'; object-src 'none'; media-src *; img-src *; style-src *; frame-ancestors 'self'"; +} + +// set outgoing proxy +if(app.conf.proxy) { +process.env.HTTP_PROXY = app.conf.proxy; +// if there is a list of domains which should +// not be proxied, set it +if(app.conf.no_proxy_list) { +if(Array.isArray(app.conf.no_proxy_list)) { +process.env.NO_PROXY = app.conf.no_proxy_list.join(','); +} else { +process.env.NO_PROXY = app.conf.no_proxy_list; +} +} +} + +// set up header whitelisting for logging +if(!app.conf.log_header_whitelist) { +app.conf.log_header_whitelist = [ +'cache-control', 'content-type', 'content-length', 'if-match', +'user-agent', 'x-request-id' +]; +} +app.conf.log_header_whitelist = new RegExp('^(?:' + app.conf.log_header_whitelist.map(function(item) { +return item.trim(); +}).join('|') + ')$', 'i'); + +// set up the spec +if(!app.conf.spec) { +app.conf.spec = __dirname + '/spec.yaml'; +} +if(app.conf.spec.constructor !== Object) { +try { +app.conf.spec = yaml.safeLoad(fs.readFileSync(app.conf.spec)); +} catch(e) { +app.logger.log('warn/spec', 'Could not load the spec: ' + e); +app.conf.spec = {}; +} +} +if(!app.conf.spec.swagger) { +app.conf.spec.swagger = '2.0'; +} +if(!app.conf.spec.info) { +app.conf.spec.info = { +version: app.info.version, +title: app.info.name, +description: app.info.description +}; +} +app.conf.spec.info.version = app.info.version; +if(!app.conf.spec.paths) { +app.conf.spec.paths = {}; +} + +// set the CORS and CSP headers +app.all('*', function(req, res, next) { +// +// Tilerator is an admin app, there is no point to set app.conf.cors and app.conf.csp +// +sUtil.initAndLogRequest(req, app); +next(); +}); + +// disable the X-Powered-By header +app.set('x-powered-by', false); +// disable the ETag header - users should provide them! +app.set('etag', false); +// enable compression +app.use(compression({level: app.conf.compression_level})); +// use the JSON body parser +app.use(bodyParser.json()); +// use the application/x-www-form-urlencoded parser +app.use(bodyParser.urlencoded({extended: true})); + +return BBPromise.resolve(app); + +} + + +/** + * Loads all routes declared in