Advertisement
aleffelixf

server.ts

Mar 18th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import {ApolloServer} from 'apollo-server'
  2. import {ApolloGateway} from '@apollo/gateway'
  3. import AuthenticatedDataSource from './middlewares/AuthenticatedDataSource'
  4.  
  5. const runServer = async () => {
  6. const server = new ApolloServer({
  7. gateway: new ApolloGateway({
  8. buildService: ({url}) => new AuthenticatedDataSource({url}),
  9. serviceList: [{
  10. name: 'crm',
  11. url: 'http://localhost:7000/api/v1',
  12. }],
  13. }),
  14. subscriptions: false,
  15. context: ({req}) => {
  16. const token = req.headers.authorization || ''
  17. return {token}
  18. }
  19. })
  20.  
  21. const {url} = await server.listen()
  22.  
  23. console.log(`Server ready at ${url}`)
  24. }
  25.  
  26. runServer().catch(error => {
  27. console.error(`Failed to start server: `, error)
  28. process.exit(1)
  29. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement