Closed ericzon closed 1 year ago
Well, I don't think that is possible right now to provide plugins from conf.json.
Try looking at this issue: https://github.com/axa-group/nlp.js/issues/414
Invoking @nfreear as he developed the plugin part for the express-api-server, and let's debate: "how we want to provide middlewares to express?"
Well, I was able to add plugins without touching the library, just using "pathPlugins" field. For me it's not so much declarative but it works perfectly and is not intrusive.
I put here an example:
conf.json
{
pathPlugins: "./src/plugins",
settings: {
nlp: {
forceNER: true
},
ner: {},
'api-server': {
'port': 3000,
'serveBot': true
}
},
use: [
'Basic',
'LangEn',
'Nlp',
'ExpressApiServer',
'DirectlineConnector',
'Bot'
]
}
./src/plugins/test-plugin.js
const myMiddleware = (req, res, next) => {
console.log('###> req info: ', req.path);
next();
};
class TestPlugin {
constructor({ container }) {
const apiServer = container.get('api-server')
console.trace('TestPlugin! > container', apiServer);
apiServer.plugins = [...apiServer.plugins, myMiddleware]
}
}
module.exports = TestPlugin;
If you prefer I can send a PR to document this.
For me an alternative definition more declarative (although both could work in a complementary way) should be something plugin scoped like this:
conf.json
{
pathPlugins: "./src/plugins",
settings: {
nlp: {
forceNER: true
},
ner: {},
'api-server': {
'port': 3000,
'serveBot': true
}
},
use: [
...
{
className: 'ExpressApiServer',
--> plugins: ['...my custom path/myPlugin1.js', '...my custom path/myPlugin2.js', '...my custom path/myPlugin3.js']
}
...
]
}
Closing due to inactivity. Please, re-open if you think the topic is still alive.
Description
Hi, I've been searching in the examples and the docs but I didn't found the answer. How can I pass a list of plugins to express-api-server on dockStart(...)?
I tried to pass on each of these 2 places but nothing arrives to class constructor, only the settings (I use cors as a simple example):
In the code I see this: https://github.com/axa-group/nlp.js/blob/fc8b61078c04a0627c3e8585912d6fcfb399b1a2/packages/express-api-server/src/express-api-server.js#L48
it shouldn't be better something like this?