a minimal refactoring of the entrypoint

This commit is contained in:
Nikola Bjelo committed 2018-11-01 08:04:53 +01:00
1 parent faa235dc02
commit c2960123ee
4 files changed
+65 -55

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import 'dotenv/config';
import express from 'express';
import cors from 'cors';
import graphqlHTTP from 'express-graphql';
import expressPlayground from 'graphql-playground-middleware-express';
import * as Sentry from '@sentry/node';
import schema from './schema';
const app = express();
// Initialising sentry
Sentry.init({ dsn: process.env.SENTRY_DNS });
app.use(Sentry.Handlers.requestHandler());
// authorising CORS
app.use(cors());
// Starting the graphql server
app.use('/graphql', graphqlHTTP(req => ({
schema,
context: {
userId: req.headers.userid,
authorization: req.headers.authorization,
},
formatError(err) {
return {
message: err.message,
code: err.originalError && err.originalError.code,
path: err.path,
};
},
})));
// Starting the graphql server
app.get('/playground', expressPlayground({ endpoint: '/graphql' }));
// Sentry error handling middleware if anything pass through
app.use(Sentry.Handlers.errorHandler());
export default app;