import * as Sentry from "@sentry/node" ; import { ApolloServer } from "apollo-server-express" ; import bodyParser from "body-parser" ; import cors from "cors" ; import express from "express" ; import prometheusMiddleware from "express-prometheus-middleware" ; import depthLimit from "graphql-depth-limit" ; import { createServer } from "http" ; import restAPI from "./rest-api" ; import schema from "./schema" ; import ENV from "./tools/server-env" ; import { requestErrorHandler , requestLogger } from "./tools/server-utils" ; /** ===========================================================================
 * Server Configuration
 * ============================================================================
 */ Sentry . init ( { dsn : ENV . SENTRY_DSN } ) ; const app = express ( ) ; app . use ( prometheusMiddleware ( { metricsPath : "/metrics" , collectDefaultMetrics : true , requestDurationBuckets : [ 0.1 , 0.5 , 1 , 1.5 ] , } ) ) ; app . disable ( "x-powered-by" ) ; const server = new ApolloServer ( { schema , formatError : requestErrorHandler , introspection : ENV . ENABLE_GRAPHIQL , validationRules : [ depthLimit ( 7 ) ] , } ) ; app . use ( "*" , cors ( ) ) ; app . use ( bodyParser . json ( ) ) ; app . use ( "/api" , restAPI ) ; app . use ( "/graphql" , requestLogger ) ; server . applyMiddleware ( { app , path : "/graphql" } ) ; const httpServer = createServer ( app ) ; httpServer . listen ( { port : ENV . PORT } , ( ) : void => console . log ( `\nGraphQL is now running${ ENV . RECORD_CLIENT_DATA ? " in mock recording mode" : "" } on http://localhost:${ ENV . PORT }/graphql\n` ) ) ;