refactor(frontend-integration): inline-import http-proxy-middleware

If no dev-dependencies are installed, the unconditional
import crashes the app.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-02-12 14:13:57 +01:00
parent 4f40366e91
commit 2ae8b0c44f
2 changed files with 5 additions and 4 deletions

View file

@ -52,7 +52,7 @@ async function bootstrap(): Promise<void> {
`Serving OpenAPI docs for private api under '/private/apidoc'`,
'AppBootstrap',
);
setupFrontendProxy(app, logger);
await setupFrontendProxy(app, logger);
}
await setupSpecialGroups(app);

View file

@ -4,19 +4,20 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { NestExpressApplication } from '@nestjs/platform-express';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { ConsoleLoggerService } from '../logger/console-logger.service';
import { useUnless } from './use-unless';
export function setupFrontendProxy(
export async function setupFrontendProxy(
app: NestExpressApplication,
logger: ConsoleLoggerService,
): void {
): Promise<void> {
logger.log(
`Setting up proxy to frontend dev server on port 3001`,
'setupFrontendProxy',
);
const createProxyMiddleware = (await import('http-proxy-middleware'))
.createProxyMiddleware;
const frontendProxy = createProxyMiddleware({
logProvider: () => {
return {