mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 06:26:26 +00:00
chore(addons): well-known gate wraps only the addon read in a request context; drop unused test factories
This commit is contained in:
@@ -42,13 +42,23 @@ export function createMcpMetadataMiddleware(
|
||||
// helper and its rejection is handed to next() — the same error path a
|
||||
// synchronous throw took before (recipe R1.5).
|
||||
return (req, res, next) => {
|
||||
void withRequestContext(orm, async () => {
|
||||
if (req.path.startsWith('/.well-known/') && !(await addons.isAddonEnabled(ADDON_IDS.MCP))) {
|
||||
res.status(404).end();
|
||||
return;
|
||||
}
|
||||
if (!req.path.startsWith('/.well-known/')) {
|
||||
meta.getMetaRouter()(req, res, next);
|
||||
}).catch(next);
|
||||
return;
|
||||
}
|
||||
// Only the addon read needs an ORM request context: this middleware sits
|
||||
// before Nest's per-request EntityManager fork (a pathless pre-init
|
||||
// app.use), and wrapping the router delegation too would fork an unused
|
||||
// EntityManager for every request the server answers.
|
||||
void withRequestContext(orm, () => addons.isAddonEnabled(ADDON_IDS.MCP))
|
||||
.then((enabled) => {
|
||||
if (!enabled) {
|
||||
res.status(404).end();
|
||||
return;
|
||||
}
|
||||
meta.getMetaRouter()(req, res, next);
|
||||
})
|
||||
.catch(next);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -29,21 +29,6 @@ import type { AppSettingsRepository } from '../../src/db/repositories/AppSetting
|
||||
* Nest's real DI graph (task-2-review.md I2's fix, carried forward for this
|
||||
* domain).
|
||||
*/
|
||||
export async function createTestAddonsRepo(db: Database.Database): Promise<AddonsRepository> {
|
||||
const t = await sharedTestOrm(db);
|
||||
return t.repo(Addons) as AddonsRepository;
|
||||
}
|
||||
|
||||
export async function createTestPhotoProvidersRepo(db: Database.Database): Promise<PhotoProvidersRepository> {
|
||||
const t = await sharedTestOrm(db);
|
||||
return t.repo(PhotoProviders) as PhotoProvidersRepository;
|
||||
}
|
||||
|
||||
export async function createTestPhotoProviderFieldsRepo(db: Database.Database): Promise<PhotoProviderFieldsRepository> {
|
||||
const t = await sharedTestOrm(db);
|
||||
return t.repo(PhotoProviderFields) as PhotoProviderFieldsRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* The full `AddonsService` a hand-constructed test collaborator needs, bound
|
||||
* to the suite's own better-sqlite3 handle.
|
||||
|
||||
Reference in New Issue
Block a user