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", "name": "koishi-nestjs",
"version": "1.0.30", "version": "1.0.31",
"description": "Koishi.js as Nest.js Module", "description": "Koishi.js as Nest.js Module",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
......
...@@ -33,14 +33,30 @@ export class KoishiMetascanService { ...@@ -33,14 +33,30 @@ export class KoishiMetascanService {
) {} ) {}
getHttpAdapter(): AbstractHttpAdapter { getHttpAdapter(): AbstractHttpAdapter {
const possibleHttpAdapters: AbstractHttpAdapter[] = [];
for (const module of this.moduleContainer.values()) { for (const module of this.moduleContainer.values()) {
const adapterHost = module.providers.get(HttpAdapterHost); const adapterHost = module.providers.get(HttpAdapterHost);
if (adapterHost) { if (adapterHost) {
return (adapterHost as InstanceWrapper<HttpAdapterHost>).instance const httpAdapter = (adapterHost as InstanceWrapper<HttpAdapterHost>)
.httpAdapter; .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( private async handleInstance(
...@@ -83,8 +99,9 @@ export class KoishiMetascanService { ...@@ -83,8 +99,9 @@ export class KoishiMetascanService {
); );
break; break;
case 'onevent': case 'onevent':
const { data: eventData } = const {
regData as DoRegisterConfig<EventNameAndPrepend>; data: eventData,
} = regData as DoRegisterConfig<EventNameAndPrepend>;
baseContext.on(eventData.name, (...args: any[]) => baseContext.on(eventData.name, (...args: any[]) =>
methodFun.call(instance, ...args), 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