import * as sapper from "@sapper/server" ; import compression from "compression" ; import express , { Express } from "express" ; import sirv from "sirv" ; import { createApolloServer } from "./graphql" ; const PORT = process . env . PORT ; const mode = process . env . NODE_ENV ; const dev = mode === "development" ; const createSapperAndApolloServer = async ( graphqlPath ) : Promise < Express > => { const app = express ( ) ; const apolloServer = await createApolloServer ( ) ; apolloServer . applyMiddleware ( { app , path : graphqlPath } ) ; app . use ( compression ( { threshold : 0 } ) , sirv ( "static" , { dev } ) , sapper . middleware ( ) ) ; return app ; } ; createSapperAndApolloServer ( "/graphql" ) . then ( ( app ) => { app . listen ( PORT , ( err ? ) : void => { if ( err ) console . log ( "error" , err ) ; } ) ; } ) ;