HTTPS

HTTPS

HTTPS ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜๋Š” ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค๋ ค๋ฉด ์˜ต์…˜ ๊ฐ์ฒด๋ฅผ ์ „๋‹ฌํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

const httpsOptions = {
  key: fs.readFileSync('./secrets/private-key.pem'),
  cert: fs.readFileSync('./secrets/public-certificate.pem'),
};
const app = await NestFactory.create(ApplicationModule, {
  httpsOptions,
});
await app.listen(3000);

Fastify๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ดapp๋ฅผ ๋งŒ๋“œ์‹ญ์‹œ์˜ค :

const app = await NestFactory.create<NestFastifyApplication>(
  ApplicationModule,
  new FastifyAdapter({ https: httpsOptions }),
);

Multiple simultaneous servers

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ธ์Šคํ„ด์Šค๋ฅผ ์™„์ „ํžˆ ์ œ์–ดํ•˜๋ฉด ๋‹ค๋ฅธ ํฌํŠธ์—์„œ ์ˆ˜์‹  ๋Œ€๊ธฐํ•˜๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋™์‹œ ์„œ๋ฒ„๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const httpsOptions = {
  key: fs.readFileSync('./secrets/private-key.pem'),
  cert: fs.readFileSync('./secrets/public-certificate.pem'),
};

const server = express();
const app = await NestFactory.create(
  ApplicationModule,
  new ExpressAdapter(server),
);
await app.init();

http.createServer(server).listen(3000);
https.createServer(httpsOptions, server).listen(443);

info ํžŒํŠธ ExpressAdapter๋Š” @nestjs/platform-express ํŒจํ‚ค์ง€์—์„œ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

Last updated