Open fbbdev opened 7 years ago
While I think that platform APIs (namely, register/override and the priority mechanism) reached a good point, I believe that options and base url APIs could be improved.
For options, I propose the following changes:
extendOptions
method to have the same signature of the override method: (platformName, options)
. This would make it more coherent with the rest of the API.extendOptions
to configure
. It's shorter, easier on the eyes, more explicative... like you observed in the comment setOptions
would not be a good choice, but I find extendOptions
confusing too.options
argument to the main serve
method. The use case I have in mind is that of an app that wants to provide custom defaults for options, or load them from a config file, from the environment or from command-line options. The autoserve
call seems a good place to do that, and it would still allow deployment scripts to override options; otherwise, apps would use the extendOptions
method and hide settings made by deployment scripts, since those run before the app.For the base url system I propose the following mechanism:
baseUrl
property with default value = null
if (typeof module.exports.baseUrl === 'function') {
actualBaseUrl = module.exports.baseUrl(req);
} else {
actualBaseUrl = module.exports.baseUrl || detectedPlatform.getBaseUrl(req);
}
if (req.url.indexOf(actualBaseUrl) === 0) {
req.baseUrl = actualBaseUrl;
req.url = req.url.slice(actualBaseUrl.length);
}
These changes would allow a deployment script to handle complex cases while still providing sane defaults. See notes on cbccaf2 for a discussion of related problems.
I'm opening this issue to summarize and discuss in one place all configuration APIs.
Things that currently are, or could be made, configurable:
Requirements:
serve
Current APIs:
autoserve.register(platform)
autoserve.override(platformName, object)
{ /*platform object*/ }.priority
autoserve.override(platformName, { priority: /* new priority */ })
autoserve.options[ /* platform name */ ]
andautoserve.extendOptions(object)
{ /* platform object */ }.getBaseUrl(request)