com.jimuwd.xian.registry-proxy 1.0.12 → 1.0.13

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 CHANGED
@@ -110,7 +110,6 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
110
110
  res.writeHead(400).end('Invalid Request');
111
111
  return;
112
112
  }
113
- // Handle base path
114
113
  const fullUrl = new URL(req.url, `${proxyConfig.https ? 'https' : 'http'}://${req.headers.host}`);
115
114
  if (basePath && !fullUrl.pathname.startsWith(basePath)) {
116
115
  res.writeHead(404).end('Not Found');
@@ -122,9 +121,12 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
122
121
  console.log(`Proxying: ${relativePath}`);
123
122
  const responses = await Promise.all(registries.map(async ({ url, token }) => {
124
123
  try {
125
- const targetUrl = `${url}${relativePath}${fullUrl.search || ''}`;
124
+ const cleanRelativePath = relativePath.replace(/\/+$/, '');
125
+ const targetUrl = `${url}${cleanRelativePath}${fullUrl.search || ''}`;
126
+ console.log(`Fetching from: ${targetUrl}`);
126
127
  const headers = token ? { Authorization: `Bearer ${token}` } : undefined;
127
128
  const response = await fetch(targetUrl, { headers });
129
+ console.log(`Response from ${url}: ${response.status} ${response.statusText}`);
128
130
  return response.ok ? response : null;
129
131
  }
130
132
  catch (e) {
@@ -134,7 +136,8 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
134
136
  }));
135
137
  const successResponse = responses.find((r) => r !== null);
136
138
  if (!successResponse) {
137
- res.writeHead(404).end('Not Found');
139
+ console.error(`All registries failed for ${relativePath}`);
140
+ res.writeHead(404).end('Not Found - All upstream registries failed');
138
141
  return;
139
142
  }
140
143
  const contentType = successResponse.headers.get('Content-Type') || 'application/octet-stream';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "description": "A lightweight npm registry proxy with fallback support",
6
6
  "main": "dist/index.js",
package/src/index.ts CHANGED
@@ -144,7 +144,6 @@ export async function startProxyServer(
144
144
  return;
145
145
  }
146
146
 
147
- // Handle base path
148
147
  const fullUrl = new URL(req.url, `${proxyConfig.https ? 'https' : 'http'}://${req.headers.host}`);
149
148
  if (basePath && !fullUrl.pathname.startsWith(basePath)) {
150
149
  res.writeHead(404).end('Not Found');
@@ -154,15 +153,17 @@ export async function startProxyServer(
154
153
  const relativePath = basePath
155
154
  ? fullUrl.pathname.slice(basePath.length)
156
155
  : fullUrl.pathname;
157
-
158
156
  console.log(`Proxying: ${relativePath}`);
159
157
 
160
158
  const responses = await Promise.all(
161
159
  registries.map(async ({ url, token }) => {
162
160
  try {
163
- const targetUrl = `${url}${relativePath}${fullUrl.search || ''}`;
161
+ const cleanRelativePath = relativePath.replace(/\/+$/, '');
162
+ const targetUrl = `${url}${cleanRelativePath}${fullUrl.search || ''}`;
163
+ console.log(`Fetching from: ${targetUrl}`);
164
164
  const headers = token ? { Authorization: `Bearer ${token}` } : undefined;
165
165
  const response = await fetch(targetUrl, { headers });
166
+ console.log(`Response from ${url}: ${response.status} ${response.statusText}`);
166
167
  return response.ok ? response : null;
167
168
  } catch (e) {
168
169
  console.error(`Failed to fetch from ${url}:`, e);
@@ -173,7 +174,8 @@ export async function startProxyServer(
173
174
 
174
175
  const successResponse = responses.find((r): r is Response => r !== null);
175
176
  if (!successResponse) {
176
- res.writeHead(404).end('Not Found');
177
+ console.error(`All registries failed for ${relativePath}`);
178
+ res.writeHead(404).end('Not Found - All upstream registries failed');
177
179
  return;
178
180
  }
179
181