Commit 25a06f04 authored by nanahira's avatar nanahira

change logic of http adapter scan

parent 98405ccc
Pipeline #6154 passed with stages
in 38 seconds
{
"name": "koishi-nestjs",
"version": "1.0.30",
"version": "1.0.31",
"description": "Koishi.js as Nest.js Module",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
......
......@@ -33,14 +33,30 @@ export class KoishiMetascanService {
) {}
getHttpAdapter(): AbstractHttpAdapter {
const possibleHttpAdapters: AbstractHttpAdapter[] = [];
for (const module of this.moduleContainer.values()) {
const adapterHost = module.providers.get(HttpAdapterHost);
if (adapterHost) {
return (adapterHost as InstanceWrapper<HttpAdapterHost>).instance
.httpAdapter;
const httpAdapter = (adapterHost as InstanceWrapper<HttpAdapterHost>)
.instance.httpAdapter;
possibleHttpAdapters.push(httpAdapter);
}
}
return null;
if (!possibleHttpAdapters.length) {
return null;
}
// Try those adapters one by one
const adapterTypesToTry = ['express', 'fastify', 'koa'];
for (const adapterType of adapterTypesToTry) {
const foundAdapter = possibleHttpAdapters.find(
(adapter) => adapter.getType() === adapterType,
);
if (foundAdapter) {
return foundAdapter;
}
}
// Fallback to first adapter
return possibleHttpAdapters[0];
}
private async handleInstance(
......@@ -83,8 +99,9 @@ export class KoishiMetascanService {
);
break;
case 'onevent':
const { data: eventData } =
regData as DoRegisterConfig<EventNameAndPrepend>;
const {
data: eventData,
} = regData as DoRegisterConfig<EventNameAndPrepend>;
baseContext.on(eventData.name, (...args: any[]) =>
methodFun.call(instance, ...args),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment