# All files / dist/indexer-management server.js

26.83% Statements 11/41
40.91% Branches 9/22
6.67% Functions 1/15
32.35% Lines 11/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    3x

    3x
    12x

    3x
    3x
    3x
    3x
    3x
    3x
    3x
    3x

     "use strict";
    var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    };
    var __importDefault = (this && this.__importDefault) || function (mod) {
        return (mod && mod.__esModule) ? mod : { "default": mod };
    };
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.createIndexerManagementServer = void 0;
    const stream_1 = require("stream");
    const express_1 = __importDefault(require("express"));
    const cors_1 = __importDefault(require("cors"));
    const body_parser_1 = __importDefault(require("body-parser"));
    const morgan_1 = __importDefault(require("morgan"));
    exports.createIndexerManagementServer = ({ logger, client, port, }) => __awaiter(void 0, void 0, void 0, function* () {
        logger = logger.child({ component: 'IndexerManagementServer' });
        const loggerStream = new stream_1.Stream.Writable();
        loggerStream._write = (chunk, _, next) => {
            logger.debug(chunk.toString().trim());
            next();
        };
        const server = express_1.default();
        // Log requests to the logger stream
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        server.use(morgan_1.default('tiny', { stream: loggerStream }));
        server.use(cors_1.default());
        // Endpoint for health checks
        server.get('/', (_, res) => {
            res.status(200).send('Ready to roll!');
        });
        // GraphQL endpoint
        server.post('/', body_parser_1.default.json(), (req, res) => __awaiter(void 0, void 0, void 0, function* () {
            const { query, variables } = req.body;
            const result = query.startsWith('mutation')
                ? yield client.mutation(query, variables).toPromise()
                : yield client.query(query, variables).toPromise();
            res.status(200).send({
                data: result.data,
                errors: result.error ? result.error.graphQLErrors : null,
                extensions: result.extensions,
            });
        }));
        server.listen(port, () => {
            logger.debug(`Listening on port ${port}`);
        });
        return server;
    });
    //# sourceMappingURL=server.js.map