express-gateway
express-gateway copied to clipboard
Model schemas are strictly required even when auth policies are not used.
https://github.com/ExpressGateway/express-gateway/blob/2b0e5e746970e30f91ec9bb367a670e073d87eeb/lib/config/index.js#L11
EG is using a singleton config object. It attempts to load models early, even if no auth policies are used. This means users MUST include models no matter what.
Consider relaxing this requirement and look at lazy-loading based on runtime needs.
Are the models exclusively used by the Admin Server or are they also tied policies or other parts of they system?
If the former case, then this seems like a simple case of removing config.loadModels();
from config/index.js
and adding the following to config.js
:
loadConfig (type) {
// ...load config object
if (type === 'gateway' && config.admin) {
this.loadModels();
}
//...
}
As well ad addressing the dereferencePromise
in services/consumers/credentials/credential.service.js
which assumes that the models exist.
const dereferencePromise = refParser.dereference(config.models.credentials).then(derefSchema => mergeAllOf(derefSchema));
Would that work?
This is going to require some work on our side. @jtsampson you correctly identified two spots where changing the strategy from eager to lazy loading would break, but I'm almost sure there would be other places.
I think the first place where we should start changing the code is the one that is looping through the policies
array — and see if we can avoid to load there.
Perhaps (perhaps) — that array is completely useless as we can discovery the policies to load by ourselves. Once this'll be scheduled, I'll have a further look into.