diff --git a/server/.env.example b/server/.env.example index a96aeb926..81868d2aa 100644 --- a/server/.env.example +++ b/server/.env.example @@ -1,3 +1,5 @@ +PRESHARED_GATEWAY_KEY=SECRET_STUFF + PORT=3000 DB_USERNAME=example_name DB_PASSWORD=example_password diff --git a/server/src/app.js b/server/src/app.js index 56654310a..2a53b0250 100644 --- a/server/src/app.js +++ b/server/src/app.js @@ -3,6 +3,7 @@ import express from 'express'; import { ApolloServer } from 'apollo-server-express'; import * as Sentry from '@sentry/node'; import schema from './schema'; +import wrongPreshared from './errors/notAllowed.json'; const app = express(); @@ -10,6 +11,14 @@ const app = express(); Sentry.init({ dsn: process.env.SENTRY_DNS }); app.use(Sentry.Handlers.requestHandler()); +app.post('/graphql', (req, res, next) => { + if (req.headers.preshared === process.env.PRESHARED_GATEWAY_KEY) { + next(); + } else { + res.send(wrongPreshared); + } +}); + // Starting the graphql server const server = new ApolloServer({ diff --git a/server/src/errors/notAllowed.json b/server/src/errors/notAllowed.json new file mode 100644 index 000000000..b76604aa2 --- /dev/null +++ b/server/src/errors/notAllowed.json @@ -0,0 +1,8 @@ +{ + "errors": [ + { + "code": 401, + "message": "Wait, you're not supposed to be here, go through the gate as everyone else" + } + ] +}