Adding a preshared key verification middleware
This commit is contained in:
1 parent
d58ffd0219
commit
fa02ee7593
3 files changed
+19
No files matched your search
@@ -1,3 +1,5 @@
|
||||
PRESHARED_GATEWAY_KEY=SECRET_STUFF
|
||||
|
||||
PORT=3000
|
||||
DB_USERNAME=example_name
|
||||
DB_PASSWORD=example_password
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": 401,
|
||||
"message": "Wait, you're not supposed to be here, go through the gate as everyone else"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user