UNPKG

deth

Version:

Ethereum node focused on Developer Experience

44 lines (43 loc) 1.83 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const body_parser_1 = __importDefault(require("body-parser")); const restless_1 = require("@restless/restless"); const middlewares_1 = require("./rpc/middlewares"); const errorHandler_1 = require("./errorHandler"); const schema_1 = require("./rpc/schema"); const rpcExecutor_1 = require("./rpc/rpcExecutor"); const ctx_1 = require("./ctx"); const loader_1 = require("../config/loader"); const RealFileSystem_1 = require("../fs/RealFileSystem"); function getApp(ctx) { const rpcExecutor = rpcExecutor_1.rpcExecutorFromCtx(ctx); const app = express_1.default(); app.use(body_parser_1.default.json({ type: '*/*' })); app.post('/', restless_1.asyncHandler(middlewares_1.sanitizeRPCEnvelope(), middlewares_1.sanitizeRPC(schema_1.rpcCommandsDescription), middlewares_1.executeRPC(rpcExecutor), middlewares_1.respondRPC(schema_1.rpcCommandsDescription))); app.use('/health', (req, res) => { res.status(200).json({ status: 'OK', }); }); app.use('*', (_req, _res) => { throw new errorHandler_1.NotFoundHttpError(); }); app.use(errorHandler_1.errorHandler); return app; } exports.getApp = getApp; async function runNode(port, configPath) { const fs = new RealFileSystem_1.RealFileSystem(); if (configPath) { console.log(`Using ${configPath}...`); } const ctx = await ctx_1.makeDefaultCtx(configPath && loader_1.loadConfig(fs, configPath)); ctx.logger.logNodeInfo(ctx.walletManager); const app = getApp(ctx); return app.listen(port); } exports.runNode = runNode;