index.ts: schema without token

Signed-off-by: leonnicolas <leonloechner@gmx.de>
pull/14/head
leonnicolas 4 years ago
parent 478b4b688d
commit 5f19ddbb1b

@ -32,6 +32,7 @@
}, },
"dependencies": { "dependencies": {
"apollo-server-express": "^2.17.0", "apollo-server-express": "^2.17.0",
"body-parser": "^1.19.0",
"cors": "^2.8.5", "cors": "^2.8.5",
"crc": "^3.8.0", "crc": "^3.8.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",

@ -36,6 +36,7 @@ import workshopResolvers from './resolvers/workshopResolvers';
import { ActionLog } from './model/ActionLog'; import { ActionLog } from './model/ActionLog';
import actionLogResolvers from './resolvers/actionLogResolvers'; import actionLogResolvers from './resolvers/actionLogResolvers';
import { ActionLogAPI } from './datasources/db/actionLogAPI'; import { ActionLogAPI } from './datasources/db/actionLogAPI';
import bodyParser from 'body-parser';
const cors = require('cors'); const cors = require('cors');
require('dotenv').config(); require('dotenv').config();
@ -71,7 +72,9 @@ const connOptions: ConnectionOptions = {
* @param next * @param next
*/ */
async function authenticate (req: any, res: any, next: any) { async function authenticate (req: any, res: any, next: any) {
if (process.env.NODE_ENV === 'develop') { if (req.body.operationName === 'IntrospectionQuery') {
next();
} else if (process.env.NODE_ENV === 'develop') {
req.permissions = requiredPermissions.map((e) => e.name); req.permissions = requiredPermissions.map((e) => e.name);
req.userId = await userAPI.getUserId(req.headers.authorization?.replace('Bearer ', '')); req.userId = await userAPI.getUserId(req.headers.authorization?.replace('Bearer ', ''));
next(); next();
@ -132,6 +135,7 @@ const server = new ApolloServer({
const app = express(); const app = express();
app.use(cors()); app.use(cors());
app.use(bodyParser.json());
app.post('/graphql', authenticate); app.post('/graphql', authenticate);
app.get(/\/graphql?&.*query=/, authenticate); app.get(/\/graphql?&.*query=/, authenticate);

Loading…
Cancel
Save