com.jimuwd.xian.registry-proxy 1.0.107 → 1.0.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -130,14 +130,17 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
|
|
|
130
130
|
mergedHeaders.host = upstreamHost;
|
|
131
131
|
}
|
|
132
132
|
const response = await fetch(targetUrl, { headers: mergedHeaders });
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
133
|
+
if (response.ok) {
|
|
134
|
+
logger.debug(`Success response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
135
|
+
content-type=${response.headers.get('content-type')} content-encoding=${response.headers.get('content-encoding')} content-length=${response.headers.get('content-length')} transfer-encoding=${response.headers.get('transfer-encoding')}`);
|
|
136
|
+
return response;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
logger.info(`Failure response from upstream ${targetUrl}: ${response.status} ${response.statusText}
|
|
140
|
+
content-type=${response.headers.get('content-type')} content-encoding=${response.headers.get('content-encoding')} content-length=${response.headers.get('content-length')} transfer-encoding=${response.headers.get('transfer-encoding')}
|
|
141
|
+
body=${await response.text()}`);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
141
144
|
}
|
|
142
145
|
catch (e) {
|
|
143
146
|
if (e instanceof Error) {
|
|
@@ -155,7 +158,7 @@ async function fetchFromRegistry(registry, targetUrl, reqFromDownstreamClient, l
|
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
160
|
async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDownstreamClient, upstreamResponse, reqFromDownstreamClient, proxyInfo, proxyPort, registryInfos) {
|
|
158
|
-
logger.info(`Writing upstream registry server ${registryInfo.normalizedRegistryUrl}'s
|
|
161
|
+
logger.info(`Writing upstream registry server ${registryInfo.normalizedRegistryUrl}'s ${upstreamResponse.status}${upstreamResponse.statusText ? (' "' + upstreamResponse.statusText + '"') : ''} response to downstream client.`);
|
|
159
162
|
if (!upstreamResponse.ok)
|
|
160
163
|
throw new Error("Only 2xx upstream response is supported");
|
|
161
164
|
try {
|
|
@@ -250,7 +253,7 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
250
253
|
// pipe upstream body to downstream client
|
|
251
254
|
upstreamResponse.body.pipe(resToDownstreamClient, { end: true });
|
|
252
255
|
upstreamResponse.body
|
|
253
|
-
.on('data', (chunk) => logger.
|
|
256
|
+
.on('data', (chunk) => logger.debug(`Chunk transferred from ${targetUrl} to downstream client size=${chunk.length}`))
|
|
254
257
|
.on('end', () => {
|
|
255
258
|
logger.info(`Upstream server ${targetUrl} response.body ended.`);
|
|
256
259
|
// resToDownstreamClient.end();
|
|
@@ -393,11 +396,12 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
393
396
|
reject(err);
|
|
394
397
|
});
|
|
395
398
|
server.on('connection', (socket) => {
|
|
396
|
-
logger.
|
|
399
|
+
logger.info("Server on connection");
|
|
397
400
|
socket.setTimeout(60000);
|
|
398
401
|
socket.setKeepAlive(true, 30000);
|
|
399
402
|
});
|
|
400
|
-
|
|
403
|
+
// ipv4和ipv6双栈支持
|
|
404
|
+
server.listen(port, '::', () => {
|
|
401
405
|
const address = server.address();
|
|
402
406
|
proxyPort = address.port;
|
|
403
407
|
const portFile = join(process.env.PROJECT_ROOT || process.cwd(), '.registry-proxy-port');
|