Files
public-pool/src/main.ts
T
Thomas Shufps 2aa0ebe587 some changes for docker setup (#9)
* added SIGTERM handler for graceful docker shutdown

* added error message

* added example for bitcoind running on the host undockered

* added docker-compose and extended example

* added docker-compose section to README

* addes some note for rpcallowip

* added restart policy

* added DB folder for persistent data

* added $NETWORK as prefix for database path to not get in conflict with testnet setup

* used env variables for stratum and api ports
2023-11-19 14:16:50 -05:00

64 lines
1.6 KiB
TypeScript

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<NestFastifyApplication>(AppModule, new FastifyAdapter(options));
app.setGlobalPrefix('api')
app.useGlobalPipes(
new ValidationPipe({
transform: true,
whitelist: true,
forbidNonWhitelisted: true,
forbidUnknownValues: true
}),
);
process.on('SIGINT', () => {
console.log(`Stopping services`);
process.exit(0);
});
process.on('SIGTERM', () => {
console.log(`Stopping services`);
process.exit(0);
});
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();