相关文章推荐
跑龙套的青蛙  ·  软件中心用户指南- ...·  1 月前    · 
霸气的领结  ·  灰鸽子远程控制·  3 周前    · 
霸气的领结  ·  灰鸽子远程控制软件·  3 周前    · 
谈吐大方的火车  ·  Windows:Opencv ...·  2 年前    · 
长情的企鹅  ·  Visual studio ...·  2 年前    · 
慷慨的烈马  ·  seaborn ...·  2 年前    · 
跳到主要内容

HTTPS

To create an application that uses the HTTPS protocol, set the httpsOptions property in the options object passed to the create() method of the NestFactory class:

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

If you use the FastifyAdapter , create the application as follows:

const app = await NestFactory.create<NestFastifyApplication




    
>(
AppModule,
new FastifyAdapter({ https: httpsOptions }),
);

Multiple simultaneous servers

The following recipe shows how to instantiate a Nest application that listens on multiple ports (for example, on a non-HTTPS port and an HTTPS port) simultaneously.

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

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

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

info Hint The ExpressAdapter is imported from the @nestjs/platform-express package. The http and https packages are native Node.js packages.

Warning This recipe does not work with GraphQL Subscriptions .