import compression from "compression" ; import express , { Application } from "express" ; import bodyParser from "body-parser" ; import { ApolloServer } from "apollo-server-express" ; import { connectDatabase } from "./database" ; import { typeDefs , resolvers } from "./graphql" ; import cookieParser from "cookie-parser" ; const mount = async ( app ) => { const db = await connectDatabase ( ) ; app . use ( bodyParser . json ( { limit : "2mb" } ) ) ; app . use ( compression ( ) ) ; app . use ( cookieParser ( process . env . SECRET ) ) ; app . use ( express . static ( `${ __dirname }/client` ) ) ; app . get ( "/*" , ( _req , res ) => res . sendFile ( `${ __dirname }/client/index.html` ) ) ; const server = new ApolloServer ( { typeDefs , resolvers , context : ( { res , req } ) => ( { db , res , req } ) , } ) ; server . applyMiddleware ( { app , path : "/api" } ) ; app . listen ( process . env . PORT ) ; console . log ( `[app] : http://localhost:${ process . env . PORT }` ) ; } ; mount ( express ( ) ) ;