import { ValidationPipe } from '@nestjs/common'; 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'; async function bootstrap() { if (process.env.API_PORT == null) { console.error('It appears your environment is not configured, create and populate an .env file.'); return; } let options = {}; const secure = process.env.API_SECURE?.toLowerCase() == 'true'; if (secure) { const currentDirectory = process.cwd(); options = { https: { key: readFileSync(`${currentDirectory}/secrets/key.pem`), cert: readFileSync(`${currentDirectory}/secrets/cert.pem`), } }; } const app = await NestFactory.create(AppModule, new FastifyAdapter(options)); app.setGlobalPrefix('api') app.useGlobalPipes( new ValidationPipe({ transform: true, whitelist: true, forbidNonWhitelisted: true, forbidUnknownValues: true }), ); app.enableCors(); useContainer(app.select(AppModule), { fallbackOnErrors: true }); //Taproot bitcoinjs.initEccLib(ecc); await app.listen(process.env.API_PORT, '0.0.0.0', (err, address) => { console.log(`API listening on ${address}`); }); } bootstrap();