ifms-pti/server/src/server.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-11-06 13:31:28 +00:00
import { ApolloServer } from 'apollo-server'
import responseCachePlugin from 'apollo-server-plugin-response-cache'
2020-12-14 20:51:43 +00:00
import { ad } from './lib/activeDirectory'
2020-11-06 13:31:28 +00:00
import { typeDefs } from './typeDefs'
import { resolvers } from './resolvers'
import { schemaDirectives } from './schemaDirectives'
const server = new ApolloServer({
2022-08-08 20:56:37 +00:00
introspection: process.env.INTROSPECTION || false,
playground: {
settings: {
'editor.theme': 'light'
}
},
2020-11-06 13:31:28 +00:00
cors:
process.env.NODE_ENV === 'production'
? {
2021-01-20 12:49:45 +00:00
origin: [
'http://ifms-pti-web.paas1.pp.ifms.edu.br',
'https://ifms-pti-web.paas1.pp.ifms.edu.br',
'http://ti.pp.ifms.edu.br',
'https://ti.pp.ifms.edu.br'
]
2020-11-06 13:31:28 +00:00
}
: true,
typeDefs,
resolvers,
2020-12-03 21:27:03 +00:00
subscriptions: {
2020-12-03 21:50:25 +00:00
onConnect: connectionParams => {
return {
2020-12-04 22:40:47 +00:00
authorization: connectionParams.Authorization
2020-12-03 21:50:25 +00:00
}
}
2020-12-03 21:27:03 +00:00
},
2020-11-06 13:31:28 +00:00
schemaDirectives,
2020-12-03 21:27:03 +00:00
context: ({ req, connection }) => {
2020-11-06 13:31:28 +00:00
return {
ad,
2020-12-03 21:27:03 +00:00
connection,
2020-11-06 13:31:28 +00:00
req
}
2020-12-03 21:27:03 +00:00
},
2020-11-06 13:31:28 +00:00
plugins: [
responseCachePlugin({
2020-12-19 14:39:53 +00:00
sessionId: requestContext => {
return (
requestContext.request.http.headers.get('authorization') ||
requestContext.request.http.headers.get('Authorization') ||
null
)
}
2020-11-06 13:31:28 +00:00
})
]
})
export { server }