Explicit routes configuration

This commit is contained in:
Daniel García Aubert 2019-10-01 17:45:12 +02:00
parent 3dee09a5c5
commit 1d55de3e43
5 changed files with 69 additions and 61 deletions

View File

@ -62,21 +62,21 @@ module.exports = function serverFactory (statsClient) {
app.dataIngestionLogger = dataIngestionLogger; app.dataIngestionLogger = dataIngestionLogger;
// FIXME: health controller should be atached to the main entry point: "/" // FIXME: health controller should be atached to the main entry point: "/"
// instead of "/api/v1/" // instead of "/api/v1/" or "/user/:user/api/:version"
const healthCheckController = new HealthCheckController({ const healthCheckController = new HealthCheckController({
routes: global.settings.routes routes: global.settings.routes.api
}); });
healthCheckController.route(app); healthCheckController.route(app);
// FIXME: version controller should be atached to the main entry point: "/" // FIXME: version controller should be atached to the main entry point: "/"
// instead of "/api/v1/" // instead of "/api/:version" or "/user/:user/api/:version"
const versionController = new VersionController({ const versionController = new VersionController({
routes: global.settings.routes routes: global.settings.routes.api
}); });
versionController.route(app); versionController.route(app);
const apiRouter = new ApiRouter({ const apiRouter = new ApiRouter({
routes: global.settings.routes, routes: global.settings.routes.api,
redisPool, redisPool,
metadataBackend, metadataBackend,
statsClient, statsClient,

View File

@ -2,21 +2,23 @@
// Disable by using <=0 value. // Disable by using <=0 value.
module.exports.gc_interval = 10000; module.exports.gc_interval = 10000;
module.exports.routes = { module.exports.routes = {
paths: [ api: {
// In case the base_url has a :user param the username will be the one specified in the URL, paths: [
// otherwise it will fallback to extract the username from the host header. // In case the base_url has a :user param the username will be the one specified in the URL,
'/api/:version', // otherwise it will fallback to extract the username from the host header.
'/user/:user/api/:version', '/api/:version',
], '/user/:user/api/:version',
// Attach middlewares at the begining of the req/res cycle ],
// to perform custom operations. // Attach middlewares at the begining of the req/res cycle
middlewares: [ // to perform custom operations.
function noop () { middlewares: [
return function noopMiddleware (req, res, next) { function noop () {
next(); return function noopMiddleware (req, res, next) {
next();
}
} }
} ]
] }
}; };
// If useProfiler is true every response will be served with an // If useProfiler is true every response will be served with an
// X-SQLAPI-Profile header containing elapsed timing for various // X-SQLAPI-Profile header containing elapsed timing for various

View File

@ -2,21 +2,23 @@
// Disable by using <=0 value. // Disable by using <=0 value.
module.exports.gc_interval = 10000; module.exports.gc_interval = 10000;
module.exports.routes = { module.exports.routes = {
paths: [ api: {
// In case the base_url has a :user param the username will be the one specified in the URL, paths: [
// otherwise it will fallback to extract the username from the host header. // In case the base_url has a :user param the username will be the one specified in the URL,
'/api/:version', // otherwise it will fallback to extract the username from the host header.
'/user/:user/api/:version', '/api/:version',
], '/user/:user/api/:version',
// Attach middlewares at the begining of the req/res cycle ],
// to perform custom operations. // Attach middlewares at the begining of the req/res cycle
middlewares: [ // to perform custom operations.
function noop () { middlewares: [
return function noopMiddleware (req, res, next) { function noop () {
next(); return function noopMiddleware (req, res, next) {
next();
}
} }
} ]
] }
}; };
// If useProfiler is true every response will be served with an // If useProfiler is true every response will be served with an
// X-SQLAPI-Profile header containing elapsed timing for various // X-SQLAPI-Profile header containing elapsed timing for various

View File

@ -2,21 +2,23 @@
// Disable by using <=0 value. // Disable by using <=0 value.
module.exports.gc_interval = 10000; module.exports.gc_interval = 10000;
module.exports.routes = { module.exports.routes = {
paths: [ api: {
// In case the base_url has a :user param the username will be the one specified in the URL, paths: [
// otherwise it will fallback to extract the username from the host header. // In case the base_url has a :user param the username will be the one specified in the URL,
'/api/:version', // otherwise it will fallback to extract the username from the host header.
'/user/:user/api/:version', '/api/:version',
], '/user/:user/api/:version',
// Attach middlewares at the begining of the req/res cycle ],
// to perform custom operations. // Attach middlewares at the begining of the req/res cycle
middlewares: [ // to perform custom operations.
function noop () { middlewares: [
return function noopMiddleware (req, res, next) { function noop () {
next(); return function noopMiddleware (req, res, next) {
next();
}
} }
} ]
] }
}; };
// If useProfiler is true every response will be served with an // If useProfiler is true every response will be served with an
// X-SQLAPI-Profile header containing elapsed timing for various // X-SQLAPI-Profile header containing elapsed timing for various

View File

@ -2,21 +2,23 @@
// Disable by using <=0 value. // Disable by using <=0 value.
module.exports.gc_interval = 10000; module.exports.gc_interval = 10000;
module.exports.routes = { module.exports.routes = {
paths: [ api: {
// In case the base_url has a :user param the username will be the one specified in the URL, paths: [
// otherwise it will fallback to extract the username from the host header. // In case the base_url has a :user param the username will be the one specified in the URL,
'/api/:version', // otherwise it will fallback to extract the username from the host header.
'/user/:user/api/:version', '/api/:version',
], '/user/:user/api/:version',
// Attach middlewares at the begining of the req/res cycle ],
// to perform custom operations. // Attach middlewares at the begining of the req/res cycle
middlewares: [ // to perform custom operations.
function noop () { middlewares: [
return function noopMiddleware (req, res, next) { function noop () {
next(); return function noopMiddleware (req, res, next) {
next();
}
} }
} ]
] }
}; };
// If useProfiler is true every response will be served with an // If useProfiler is true every response will be served with an
// X-SQLAPI-Profile header containing elapsed timing for various // X-SQLAPI-Profile header containing elapsed timing for various