Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use(router.routes())
.use(router.allowedMethods());
// Handler to return bad request for all unhandled paths.
app.use((ctx, _next) => {
ctx.response.status = 400;
});
const port = process.env.SIDETREE_BITCOIN_PORT || config.port;
// initialize the blockchain service and kick-off background tasks
let server: any;
let blockchainService: SidetreeBitcoinProcessor;
try {
blockchainService = new SidetreeBitcoinProcessor(config);
// SIDETREE_TEST_MODE enables unit testing of this file by bypassing blockchain service initialization.
if (process.env.SIDETREE_TEST_MODE === 'true') {
server = app.listen(port);
} else {
blockchainService.initialize()
.then(() => {
server = app.listen(port, () => {
console.log(`Sidetree-Bitcoin node running on port: ${port}`);
});
})
.catch((error) => {
console.error(`Sidetree-Bitcoin node initialization failed with error: ${error}`);
process.exit(1);
});
}