File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,9 @@ app.use(router.allowedMethods());
220220app .listen (3001 );
221221```
222222
223- ## Build Docker Image
223+ ## Docker image
224+
225+ ### Build
224226
225227```
226228$ npm install
@@ -232,5 +234,13 @@ $ docker build . -f docker-image/Dockerfile -t apisguru/graphql-voyager
232234$ docker push apisguru/graphql-voyager
233235```
234236
237+ ### Configuration
238+
239+ You can config docker image with environment variable
240+
241+ - ` PORT ` to change listen port
242+ - ` GRAPHQL_ENDPOINT ` address of graphql API
243+ - ` HEADER ` headers to add to request, formated as 'header1=value1&header2=value2'
244+
235245## Credits
236246This tool is inspired by [ graphql-visualizer] ( https://github.com/NathanRSmith/graphql-visualizer ) project.
Original file line number Diff line number Diff line change @@ -3,7 +3,26 @@ const voyager = require('graphql-voyager/middleware');
33
44const app = express ( ) ;
55
6- app . use ( '/' , voyager . express ( { endpointUrl : process . env . GRAPHQL_ENDPOINT } ) ) ;
6+ const headersJS = ( ( ) => {
7+ if ( ! process . env . HEADERS || typeof process . env . HEADERS !== 'string' ) {
8+ return { } ;
9+ } ;
10+ const headers = { } ;
11+
12+ process . env . HEADERS . split ( '&' ) . forEach ( header => {
13+ let headerSplit = header . split ( '=' ) ;
14+
15+ if ( headerSplit . length === 2 ) {
16+ headers [ headerSplit [ 0 ] ] = headerSplit [ 1 ] ;
17+ }
18+ } ) ;
19+ return JSON . stringify ( headers ) ;
20+ } ) ( )
21+
22+ app . use ( '/' , voyager . express ( {
23+ endpointUrl : process . env . GRAPHQL_ENDPOINT ,
24+ headersJS : headersJS
25+ } ) ) ;
726
827process . on ( 'SIGINT' , function ( ) {
928 console . log ( "\nGracefully shutting down from SIGINT (Ctrl-C)" ) ;
You can’t perform that action at this time.
0 commit comments