This commit is contained in:
Ben Wilson
2023-08-09 09:29:15 -04:00
parent 10f6ffa91f
commit 1973b06515
4 changed files with 26 additions and 13 deletions
+14 -11
View File
@@ -3,6 +3,7 @@ import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import * as bitcoinjs from 'bitcoinjs-lib';
import { useContainer } from 'class-validator';
import { readFileSync } from 'fs';
import * as ecc from 'tiny-secp256k1';
import { AppModule } from './app.module';
@@ -14,20 +15,22 @@ async function bootstrap() {
return;
}
// const httpsOptions = {
// key: readFileSync('./secrets/key.pem'),
// cert: readFileSync('./secrets/cert.pem'),
// };
let options = {};
const secure = process.env.API_SECURE?.toLowerCase() == 'true';
if (secure) {
//const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter({ https: httpsOptions }));
const httpsOptions = {
key: readFileSync('./secrets/key.pem'),
cert: readFileSync('./secrets/cert.pem'),
};
// stagger startup
// if (process.env.NODE_APP_INSTANCE != null) {
// await setTimeout(parseInt(process.env.NODE_APP_INSTANCE) * 5000);
// }
options = { https: httpsOptions };
} else {
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
}
const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter(options));
app.setGlobalPrefix('api')
app.useGlobalPipes(
new ValidationPipe({
@@ -45,7 +48,7 @@ async function bootstrap() {
bitcoinjs.initEccLib(ecc);
await app.listen(process.env.PORT, '0.0.0.0', () => {
console.log(`https listening on port ${process.env.PORT}`);
console.log(`${secure ? 'https' : 'http'} listening on port ${process.env.PORT}`);
});
}