Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {ApolloServer} from 'apollo-server'
- import {ApolloGateway} from '@apollo/gateway'
- import AuthenticatedDataSource from './middlewares/AuthenticatedDataSource'
- const runServer = async () => {
- const server = new ApolloServer({
- gateway: new ApolloGateway({
- buildService: ({url}) => new AuthenticatedDataSource({url}),
- serviceList: [{
- name: 'crm',
- url: 'http://localhost:7000/api/v1',
- }],
- }),
- subscriptions: false,
- context: ({req}) => {
- const token = req.headers.authorization || ''
- return {token}
- }
- })
- const {url} = await server.listen()
- console.log(`Server ready at ${url}`)
- }
- runServer().catch(error => {
- console.error(`Failed to start server: `, error)
- process.exit(1)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement