Complete the code to enable compression middleware in a NestJS application.
import * as compression from 'compression'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.use([1]()); await app.listen(3000); }
The compression middleware compresses response bodies to improve performance. You add it to the app with app.use(compression()).
Complete the code to add security headers using Helmet in a NestJS app.
import * as helmet from 'helmet'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.use([1]()); await app.listen(3000); }
Helmet helps secure your app by setting various HTTP headers. You add it with app.use(helmet()).
Fix the error in the code to properly apply both compression and helmet middleware.
import * as compression from 'compression'; import * as helmet from 'helmet'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.use(compression()); app.use([1]); await app.listen(3000); }
You must call helmet() as a function to get the middleware. Using just helmet passes the module, not the middleware function.
Fill both blanks to create a NestJS middleware setup that uses compression and helmet with custom options.
import * as compression from 'compression'; import * as helmet from 'helmet'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.use([1]({ threshold: 1024 })); app.use([2]({ contentSecurityPolicy: false })); await app.listen(3000); }
Use compression with a threshold option to compress responses larger than 1024 bytes. Use helmet with contentSecurityPolicy: false to disable that specific header.
Fill all three blanks to configure a NestJS app with compression, helmet, and CORS middleware with options.
import * as compression from 'compression'; import * as helmet from 'helmet'; import * as cors from 'cors'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.use([1]({ level: 6 })); app.use([2]({ frameguard: { action: 'deny' } })); app.use([3]({ origin: 'https://example.com' })); await app.listen(3000); }
Use compression with a compression level option. Use helmet to set frameguard header to deny framing. Use cors to allow requests only from 'https://example.com'.