_expressbasicauth({ ^ TypeError: _expressbasicauth is not a function

24 Views Asked by At

The outsourcing client leaked the API swagger URL, so express-basic-auth was applied to prevent others from viewing the swagger docs. Then I tried to apply NestJS SWC. However, when applying SWC, the error below appears to occur.

Error details:/Users/gk/pray/dist/main.js:64 ], _expressbasicauth({ ^ TypeError: _expressbasicauth is not a function at bootstrap (/Users/gk/pray/dist/main.js:64:8)

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as serveStatic from 'serve-static';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import * as cookieParser from 'cookie-parser';
import { Logger } from '@nestjs/common';
import * as expressBasicAuth from 'express-basic-auth';
import { ConfigService } from '@nestjs/config';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const configService = app.get(ConfigService);

  app.enableCors({
    origin: '*',
    preflightContinue: false,
    credentials: true,
  });

  app.use(
    ['/docs'],
    expressBasicAuth({
      challenge: true,
      users: {
        [configService.getOrThrow('SWAGGER_USER')]:
          configService.getOrThrow('SWAGGER_PASSWORD'),
      },
    }),
  );

  const config = new DocumentBuilder()
    .setTitle('Pray-App')
    .setDescription('외주 API Docs')
    .setVersion('3.0')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('/docs', app, document);

  app.use('/image', serveStatic('image'));

  //쿠키 설정
  app.use(cookieParser());

  const port = configService.getOrThrow('SERVER_PORT');

  await app.listen(port);
  Logger.log(`Port ${port}로 서버가 켜졌습니다.`);
}
bootstrap();
0

There are 0 best solutions below