_encourageauthentication({ ^ TypeError: _encourageauthentication is not a function

After the outsourcing client inadvertently leaked the API swagger URL, a security measure using express-basic-auth was implemented to restrict access to the swagger docs. Subsequently, an attempt was made to integrate NestJS SWC into the system. However, during the integration process, a TypeError related to _expressbasicauth occurred as shown in the error details below.

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();

Answer №1

Make sure to only update the import statement:

import expressBasicAuth from 'express-basic-auth';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhancing data in a nested collection using MongoDB and Node.js

I have a data structure that looks something like this: { "_id" : ObjectId("501abaa341021dc3a1d0c70c"), "name" : "prova", "idDj" : "1", "list" : [ { "id" : 1, "votes" : 2 }, { "id ...

Combining MS SQL Server 2005 with Node.JS

As someone new to web development and with limited experience in SQL, I have embarked on a small project utilizing expressJS. My primary question is: Is it possible to connect with a database residing in an MS SQL 2005 Server using expressJS? While I have ...

What are the steps to manually activate input validation in Angular 2?

Having two inputs is the scenario here: The first input undergoes custom validator application The second input has a dynamic and editable value utilized in the custom validator If the custom validator is applied on the first input, then focus shifts to ...

Jenkins encountered difficulty locating npm

I have a Linux server with a user named "myuser". When I echo the path for this user, it shows: /home/myuser/bin:/home/myuser/.local/bin:/home/myuser/.nvm/versions/node/v6.11.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/u ...

Are there any optimized methods in mongoose for validating related documents that are more efficient than using .populate() and aggregating them together?

Considering the following data structures: Products: const productSchema = new Schema({ name: String, description: String, price: Number, steps: [{ type: Schema.Types.ObjectId, ref: 'steps' }] }); Steps: c ...

Converting nested arrays to objects via JSON transformation

I am faced with a nested JSON array structure like this: Parent: { Child1: [ {name:'grandchild1', value:'abc', checked:true}, {name:'grandchild2', value:'pqr', checked:false} ], Ch ...

Include an extra condition in an observable output

I am working with the following code snippet: getFileAsync(fieldFiles: Array<FileFields>): Observable<Array<UploadFile>> { const files = Array<UploadFile>(); const downloads = Array<Observable<any>>( ...

Can you determine the base class type based on the derived class?

I've encountered a typings issue while working on a new feature for my TypeScript library. Let's dive into the problem with the following example: class Base { ... } class User extends Base { ... } class Product extends Base { ... } class Comp ...

What exactly does ".default" signify in Angular, Typescript, or Javascript?

Could someone please clarify the significance of the ".default" in the code snippet below? I am interested in implementing this code in our project, but my understanding of the mentioned code fragment is uncertain. (I have modified my question to display ...

Having trouble implementing object type switching in Typescript

While in the process of developing an angular application, I stumbled upon a peculiar issue. Some time ago, I crafted this piece of code which performed flawlessly: selectedGeoArea: any receiveStoreEvent(event) { switch (event.constructor) { ca ...

What is the best way to eliminate a div upon component dismount in React?

Is there a way to remove a div element on component unmount using react? I created a div with the id portal in the useCallback method. Now, I want to remove it when the component unmounts. Can anyone guide me on how to achieve this? Below you can see the ...

The response body contains the right number of objects in the array, however, they are all blank

I recently embarked on a Ts.ED project utilizing TypeORM and Swagger to interact with my database. I've set up a UserController.ts file and a UserService.ts file. Within the service file, there's an async function that retrieves all users from my ...

The cloud storage platform Bitbucket Pipeline tends to overlook folders

I currently have the following pipeline set up: image: node:10.15.3 pipelines: default: - step: name: Installing caches: - node script: - rm -rf package-lock.json - rm -rf node_modu ...

The function resulted in null data being returned

What I am attempting to achieve : I am trying to submit a payment order to the payment gateway's server using Firebase functions. The placeorder() function successfully creates the order I need to retrieve the details of the placed order's dat ...

Unable to display image using EJS and Multer

While working on my node.js application, I encountered an issue with rendering the uploaded image file. I have successfully integrated multer to handle file uploads, and the images are being stored in the correct folder. However, when trying to display the ...

When changing the dropdown option on a separate page in React/Next JS, all checkboxes show the clicked style as a result of utilizing useState

I have implemented checkboxes for three different categories: "Types", "Price", and "Categories". They function correctly, with data being passed to a separate checkbox component without any issues. The problem arises when I click a checkbox and then inte ...

Comparing NestJS's StreamableFile with responseObject

What are the benefits of using Streaming Files instead of directly writing the object in the response with NestJS? const data = ...; response.writeHead(200, { "Content-Type": "text/csv", "Content-Disposition": `attachment; filename=something.csv`, }); ...

The function res.revalidate() is not a valid method within the NextResponse module of Nextjs when trying to implement on-demand

Currently, NextResponse does not support res.revalidate('/'). I am working with version v12.2.5, although this feature has been available since v12.2.0. My goal is to implement on-demand ISR using TypeScript. Learn more about on-demand Increment ...

What could be the culprit behind the database connection timeouts on our production environment with the Prisma ORM, PgBouncer, and Supabase stack?

Currently, I am utilizing the Prisma ORM and Postgres on Supabase with PgBouncer activated within our tech stack. Additionally, we are deploying our Node/Express API using Google Cloud Run. Upon analyzing production logs, it is evident that certain errors ...

Improving Image Loading Efficiency in Next.js - Enhancing Performance by Preloading Images

Currently, I am working on a project in Next.js that involves a scroll-based image loading component. The method I am using to fetch and load images dynamically based on the scroll position is causing performance problems and leading to a less than ideal u ...