@@ -4,9 +4,10 @@ import * as fs from 'fs';
4
4
import { Browser , computeExecutablePath } from '@puppeteer/browsers' ;
5
5
import { RenderGRPCPluginV2 } from './plugin/v2/grpc_plugin' ;
6
6
import { HttpServer } from './service/http-server' ;
7
+ import { populateServiceConfigFromEnv , ServiceConfig , defaultServiceConfig } from './service/config' ;
8
+ import { populatePluginConfigFromEnv , PluginConfig , defaultPluginConfig } from './plugin/v2/config' ;
7
9
import { ConsoleLogger , PluginLogger } from './logger' ;
8
10
import * as minimist from 'minimist' ;
9
- import { defaultPluginConfig , defaultServiceConfig , readJSONFileSync , PluginConfig , ServiceConfig } from './config' ;
10
11
import { serve } from './node-plugin' ;
11
12
import { createSanitizer } from './sanitizer/Sanitizer' ;
12
13
@@ -86,92 +87,8 @@ main().catch((err) => {
86
87
process . exit ( 1 ) ;
87
88
} ) ;
88
89
89
- function populatePluginConfigFromEnv ( config : PluginConfig , env : NodeJS . ProcessEnv ) {
90
- // Plugin env variables that needs to be initiated early
91
- if ( env [ 'GF_PLUGIN_GRPC_HOST' ] ) {
92
- config . plugin . grpc . host = env [ 'GF_PLUGIN_GRPC_HOST' ] as string ;
93
- }
94
-
95
- if ( env [ 'GF_PLUGIN_GRPC_PORT' ] ) {
96
- config . plugin . grpc . port = parseInt ( env [ 'GF_PLUGIN_GRPC_PORT' ] as string , 10 ) ;
97
- }
98
-
99
- if ( env [ 'GF_PLUGIN_RENDERING_CHROME_BIN' ] ) {
100
- config . rendering . chromeBin = env [ 'GF_PLUGIN_RENDERING_CHROME_BIN' ] ;
101
- }
102
- }
103
-
104
- function populateServiceConfigFromEnv ( config : ServiceConfig , env : NodeJS . ProcessEnv ) {
105
- if ( env [ 'BROWSER_TZ' ] ) {
106
- config . rendering . timezone = env [ 'BROWSER_TZ' ] ;
107
- } else if ( env [ 'TZ' ] ) {
108
- config . rendering . timezone = env [ 'TZ' ] ;
109
- }
110
-
111
- if ( env [ 'HTTP_HOST' ] ) {
112
- config . service . host = env [ 'HTTP_HOST' ] ;
113
- }
114
-
115
- if ( env [ 'HTTP_PORT' ] ) {
116
- config . service . port = parseInt ( env [ 'HTTP_PORT' ] as string , 10 ) ;
117
- }
118
-
119
- if ( env [ 'AUTH_TOKEN' ] ) {
120
- const authToken = env [ 'AUTH_TOKEN' ] as string ;
121
- config . service . security . authToken = authToken . includes ( ' ' ) ? authToken . split ( ' ' ) : authToken ;
122
- }
123
-
124
- if ( env [ 'LOG_LEVEL' ] ) {
125
- config . service . logging . level = env [ 'LOG_LEVEL' ] as string ;
126
- }
127
-
128
- if ( env [ 'IGNORE_HTTPS_ERRORS' ] ) {
129
- config . rendering . ignoresHttpsErrors = env [ 'IGNORE_HTTPS_ERRORS' ] === 'true' ;
130
- }
131
-
132
- if ( env [ 'CHROME_BIN' ] ) {
133
- config . rendering . chromeBin = env [ 'CHROME_BIN' ] ;
134
- }
90
+ function readJSONFileSync ( filePath : string ) {
91
+ const rawdata = fs . readFileSync ( filePath , 'utf8' ) ;
92
+ return JSON . parse ( rawdata ) ;
93
+ } ;
135
94
136
- if ( env [ 'ENABLE_METRICS' ] ) {
137
- config . service . metrics . enabled = env [ 'ENABLE_METRICS' ] === 'true' ;
138
- }
139
-
140
- if ( env [ 'RENDERING_MODE' ] ) {
141
- config . rendering . mode = env [ 'RENDERING_MODE' ] as string ;
142
- }
143
-
144
- if ( env [ 'RENDERING_CLUSTERING_MODE' ] ) {
145
- config . rendering . clustering . mode = env [ 'RENDERING_CLUSTERING_MODE' ] as string ;
146
- }
147
-
148
- if ( env [ 'RENDERING_CLUSTERING_MAX_CONCURRENCY' ] ) {
149
- config . rendering . clustering . maxConcurrency = parseInt ( env [ 'RENDERING_CLUSTERING_MAX_CONCURRENCY' ] as string , 10 ) ;
150
- }
151
-
152
- if ( env [ 'RENDERING_CLUSTERING_TIMEOUT' ] ) {
153
- config . rendering . clustering . timeout = parseInt ( env [ 'RENDERING_CLUSTERING_TIMEOUT' ] as string , 10 ) ;
154
- }
155
-
156
- if ( env [ 'RENDERING_VERBOSE_LOGGING' ] ) {
157
- config . rendering . verboseLogging = env [ 'RENDERING_VERBOSE_LOGGING' ] === 'true' ;
158
- }
159
-
160
- if ( env [ 'RENDERING_DUMPIO' ] ) {
161
- config . rendering . dumpio = env [ 'RENDERING_DUMPIO' ] === 'true' ;
162
- }
163
-
164
- if ( env [ 'RENDERING_VIEWPORT_PAGE_ZOOM_LEVEL' ] ) {
165
- config . rendering . pageZoomLevel = parseFloat ( env [ 'RENDERING_VIEWPORT_PAGE_ZOOM_LEVEL' ] as string ) ;
166
- }
167
-
168
- if ( env [ 'RENDERING_ARGS' ] ) {
169
- const args = env [ 'RENDERING_ARGS' ] as string ;
170
- if ( args . length > 0 ) {
171
- const argsList = args . split ( ',' ) ;
172
- if ( argsList . length > 0 ) {
173
- config . rendering . args = argsList ;
174
- }
175
- }
176
- }
177
- }
0 commit comments