Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Wait until the legacy LB3 app boots
await pEvent(legacyApp, 'booted');
}
debug('MOUNT LB3 APP');
const swaggerSpec = generateSwaggerSpec(legacyApp);
const result = await swagger2openapi.convertObj(swaggerSpec, {
// swagger2openapi options
});
const openApiSpec: OpenAPIObject = result.openapi;
// Option A: mount the entire LB3 app, including any request-preprocessing
// middleware like CORS, Helmet, loopback#token, etc.
// 1. Rebase the spec, e.g. from `GET /Products` to `GET /api/Products`.
const specInRoot = rebaseOpenApiSpec(openApiSpec, swaggerSpec.basePath);
if (debug.enabled)
debug(
'API of LB3 app',
Object.keys(specInRoot.paths)
.map(p =>
Object.keys(specInRoot.paths[p])
.map(v => `\n\t${v.toUpperCase()} ${p}`)
.join(''),
)
.join(''),
);
// 2. Mount the full Express app
this.mountExpressRouter('/', specInRoot, legacyApp);
/* Options B: mount LB3 REST handler only.
private mountFullApp(lb3App: Lb3Application, spec: OpenApiSpec) {
const restApiRoot = lb3App.get('restApiRoot') || '/';
debug('Mounting the entire LB3 app at %s', restApiRoot);
const specInRoot = rebaseOpenApiSpec(spec, restApiRoot);
this.app.mountExpressRouter('/', lb3App, specInRoot);
}