我用以下命令生成了证书。
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
以下是我在 NestJS 中使用它的方式。
const httpsOptions = {
key: fs.readFileSync('./secrets/key.pem'),
cert: fs.readFileSync('./secrets/cert.pem'),
};
const app = await NestFactory.create(AppModule, {
httpsOptions,
});
await app.listen(3000);
我遇到了以下错误。我在这里做错了什么?
(node:4868) UnhandledPromiseRejectionWarning: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
at Object.createSecureContext (_tls_common.js:149:17)
at Server.setSecureContext (_tls_wrap.js:1323:27)
at Server (_tls_wrap.js:1181:8)
at new Server (https.js:66:14)
at Object.createServer (https.js:91:10)
at ExpressAdapter.initHttpServer (C:\my-project\node_modules\@nestjs\platform-express\adapters\express-adapter.js:97:37)
at NestApplication.createServer (C:\my-project\node_modules\@nestjs\core\nest-application.js:68:26)
at NestApplication.registerHttpServer (C:\my-project\node_modules\@nestjs\core\nest-application.js:51:32)
at new NestApplication (C:\my-project\node_modules\@nestjs\core\nest-application.js:35:14)
at NestFactoryStatic.create (C:\my-project\node_modules\@nestjs\core\nest-factory.js:35:26)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at bootstrap (C:\my-project\server\main.ts:25:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4868) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 9)
(node:4868) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.