From d2c9e8bccc8241ef599e12044ce1c8c3823240f2 Mon Sep 17 00:00:00 2001 From: Francois Gerthoffert Date: Mon, 5 Jul 2021 16:43:02 -0400 Subject: [PATCH] Fixed alive method --- src/utils/graphql/client/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/utils/graphql/client/index.ts b/src/utils/graphql/client/index.ts index 82f61ed..06d6b05 100644 --- a/src/utils/graphql/client/index.ts +++ b/src/utils/graphql/client/index.ts @@ -3,6 +3,7 @@ import ApolloClient from 'apollo-client'; import { ApolloLink } from 'apollo-link'; import { HttpLink } from 'apollo-link-http'; import fetch from 'node-fetch'; +import {Base64} from 'js-base64' import { ConfigFlags } from '../../../global'; @@ -16,8 +17,7 @@ const graphqlClient = async (cmdConfig: ConfigFlags) => { const authMiddleware = new ApolloLink((operation: any, forward: any) => { operation.setContext({ headers: { - authorization: `Basic ${cmdConfig.jahiaAdminUsername}:${cmdConfig.jahiaAdminPassword}`, - Origin: cmdConfig.jahiaAdminUrl + authorization: `Basic ${Base64.btoa(cmdConfig.jahiaAdminUsername + ':' + cmdConfig.jahiaAdminPassword)}` }, }); return forward(operation).map( @@ -25,6 +25,7 @@ const graphqlClient = async (cmdConfig: ConfigFlags) => { errors: Array | undefined; data: { errors: Array }; }) => { + console.log(JSON.stringify(response)) if (response.errors !== undefined && response.errors.length > 0) { response.data.errors = response.errors; } @@ -33,7 +34,20 @@ const graphqlClient = async (cmdConfig: ConfigFlags) => { ); }); - const link = ApolloLink.from([authMiddleware, httpLink]); + const refererMiddleware = new ApolloLink((operation, forward) => { + operation.setContext(({ headers = {} }) => ({ + headers: { + ...headers, + referer: cmdConfig.jahiaAdminUrl, + } + })); + + return forward(operation); + }) + + const link = ApolloLink.from([authMiddleware, refererMiddleware, httpLink]); + + console.log(link) return new ApolloClient({ link,