Created
August 27, 2022 09:09
-
-
Save susimsek/b6421faa08dbbfddcf90f6eb7c8caffd to your computer and use it in GitHub Desktop.
Apollo Federation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const startGateway = (config, apolloGatewayConfig) => { | |
const corsOptions = { | |
origin: config.CORS_ALLOWED_ORIGINS.split(", "), | |
credentials: config.CORS_ALLOW_CREDENTIALS | |
} | |
const gateway = new ApolloGateway(apolloGatewayConfig); | |
const server = new ApolloServer({ | |
gateway, | |
cors: corsOptions, | |
csrfPrevention: false, | |
subscriptions: false, | |
cache: "bounded", | |
context: ({req}) => ({ | |
authHeaderValue: req.headers.authorization | |
}), | |
plugins: [ | |
{ | |
async serverWillStart() { | |
if (process.env.NODE_ENV !== 'development') { | |
registerService(config) | |
} | |
return { | |
async serverWillStop() { | |
if (process.env.NODE_ENV !== 'development') { | |
await unregisterService() | |
} | |
} | |
} | |
} | |
} | |
] | |
}); | |
server.listen({ | |
port: config.PORT, | |
}).then(({ url }) => { | |
console.log(`🚀 Graph Router ready at ${url}`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment