Have a default configuration of "routes" when missing environment settings. It prevents errors while deploying (if the new setting is not available yet)
This commit is contained in:
parent
51ea2b066d
commit
cec1c609c0
32
app/server-options.js
Normal file
32
app/server-options.js
Normal file
@ -0,0 +1,32 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function getServerOptions () {
|
||||
const defaults = {
|
||||
routes: {
|
||||
// Each entry corresponds with an express' router.
|
||||
// You must define at least one path. However, middlewares are optional.
|
||||
api: [{
|
||||
// Required: path where other "routers" or "controllers" will be attached to.
|
||||
paths: [
|
||||
// In case the path has a :user param the username will be the one specified in the URL,
|
||||
// otherwise it will fallback to extract the username from the host header.
|
||||
'/api/:version',
|
||||
'/user/:user/api/:version',
|
||||
],
|
||||
// Optional: attach middlewares at the begining of the router
|
||||
// to perform custom operations.
|
||||
middlewares: [],
|
||||
sql: [{
|
||||
// Required
|
||||
paths: [
|
||||
'/sql'
|
||||
],
|
||||
// Optional
|
||||
middlewares: []
|
||||
}]
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
return Object.assign({}, defaults, global.settings);
|
||||
};
|
@ -8,6 +8,7 @@ const cartodbRedis = require('cartodb-redis');
|
||||
const Logger = require('./services/logger');
|
||||
const ApiRouter = require('./controllers/api-router');
|
||||
const batchFactory = require('../batch');
|
||||
const getServerOptions = require('./server-options');
|
||||
|
||||
process.env.PGAPPNAME = process.env.PGAPPNAME || 'cartodb_sqlapi';
|
||||
|
||||
@ -16,6 +17,7 @@ require('./utils/date_to_json');
|
||||
|
||||
// jshint maxcomplexity:9
|
||||
module.exports = function createServer (statsClient) {
|
||||
const options = getServerOptions();
|
||||
const app = express();
|
||||
const redisPool = new RedisPool({
|
||||
name: 'sql-api',
|
||||
@ -65,7 +67,7 @@ module.exports = function createServer (statsClient) {
|
||||
statsClient,
|
||||
dataIngestionLogger
|
||||
});
|
||||
apiRouter.route(app, global.settings.routes.api);
|
||||
apiRouter.route(app, options.routes.api);
|
||||
|
||||
const isBatchProcess = process.argv.indexOf('--no-batch') === -1;
|
||||
|
||||
|
@ -2,14 +2,17 @@
|
||||
// Disable by using <=0 value.
|
||||
module.exports.gc_interval = 10000;
|
||||
module.exports.routes = {
|
||||
// Each entry corresponds with an express' router.
|
||||
// You must define at least one path. However, middlewares are optional.
|
||||
api: [{
|
||||
// Required: path where other "routers" or "controllers" will be attached to.
|
||||
paths: [
|
||||
// In case the path has a :user param the username will be the one specified in the URL,
|
||||
// otherwise it will fallback to extract the username from the host header.
|
||||
'/api/:version',
|
||||
'/user/:user/api/:version',
|
||||
],
|
||||
// Attach middlewares at the begining of the req/res cycle
|
||||
// Optional: attach middlewares at the begining of the router
|
||||
// to perform custom operations.
|
||||
middlewares: [
|
||||
function noop () {
|
||||
@ -19,9 +22,12 @@ module.exports.routes = {
|
||||
}
|
||||
],
|
||||
sql: [{
|
||||
// Required
|
||||
paths: [
|
||||
'/sql'
|
||||
]
|
||||
],
|
||||
// Optional
|
||||
middlewares: []
|
||||
}]
|
||||
}]
|
||||
};
|
||||
|
@ -2,14 +2,17 @@
|
||||
// Disable by using <=0 value.
|
||||
module.exports.gc_interval = 10000;
|
||||
module.exports.routes = {
|
||||
// Each entry corresponds with an express' router.
|
||||
// You must define at least one path. However, middlewares are optional.
|
||||
api: [{
|
||||
// Required: path where other "routers" or "controllers" will be attached to.
|
||||
paths: [
|
||||
// In case the path has a :user param the username will be the one specified in the URL,
|
||||
// otherwise it will fallback to extract the username from the host header.
|
||||
'/api/:version',
|
||||
'/user/:user/api/:version',
|
||||
],
|
||||
// Attach middlewares at the begining of the req/res cycle
|
||||
// Optional: attach middlewares at the begining of the router
|
||||
// to perform custom operations.
|
||||
middlewares: [
|
||||
function noop () {
|
||||
@ -19,9 +22,12 @@ module.exports.routes = {
|
||||
}
|
||||
],
|
||||
sql: [{
|
||||
// Required
|
||||
paths: [
|
||||
'/sql'
|
||||
]
|
||||
],
|
||||
// Optional
|
||||
middlewares: []
|
||||
}]
|
||||
}]
|
||||
};
|
||||
|
@ -2,14 +2,17 @@
|
||||
// Disable by using <=0 value.
|
||||
module.exports.gc_interval = 10000;
|
||||
module.exports.routes = {
|
||||
// Each entry corresponds with an express' router.
|
||||
// You must define at least one path. However, middlewares are optional.
|
||||
api: [{
|
||||
// Required: path where other "routers" or "controllers" will be attached to.
|
||||
paths: [
|
||||
// In case the path has a :user param the username will be the one specified in the URL,
|
||||
// otherwise it will fallback to extract the username from the host header.
|
||||
'/api/:version',
|
||||
'/user/:user/api/:version',
|
||||
],
|
||||
// Attach middlewares at the begining of the req/res cycle
|
||||
// Optional: attach middlewares at the begining of the router
|
||||
// to perform custom operations.
|
||||
middlewares: [
|
||||
function noop () {
|
||||
@ -19,9 +22,12 @@ module.exports.routes = {
|
||||
}
|
||||
],
|
||||
sql: [{
|
||||
// Required
|
||||
paths: [
|
||||
'/sql'
|
||||
]
|
||||
],
|
||||
// Optional
|
||||
middlewares: []
|
||||
}]
|
||||
}]
|
||||
};
|
||||
|
@ -2,14 +2,17 @@
|
||||
// Disable by using <=0 value.
|
||||
module.exports.gc_interval = 10000;
|
||||
module.exports.routes = {
|
||||
// Each entry corresponds with an express' router.
|
||||
// You must define at least one path. However, middlewares are optional.
|
||||
api: [{
|
||||
// Required: path where other "routers" or "controllers" will be attached to.
|
||||
paths: [
|
||||
// In case the path has a :user param the username will be the one specified in the URL,
|
||||
// otherwise it will fallback to extract the username from the host header.
|
||||
'/api/:version',
|
||||
'/user/:user/api/:version',
|
||||
],
|
||||
// Attach middlewares at the begining of the req/res cycle
|
||||
// Optional: attach middlewares at the begining of the router
|
||||
// to perform custom operations.
|
||||
middlewares: [
|
||||
function noop () {
|
||||
@ -19,9 +22,12 @@ module.exports.routes = {
|
||||
}
|
||||
],
|
||||
sql: [{
|
||||
// Required
|
||||
paths: [
|
||||
'/sql'
|
||||
]
|
||||
],
|
||||
// Optional
|
||||
middlewares: []
|
||||
}]
|
||||
}]
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user