com.jimuwd.xian.registry-proxy 1.0.28 → 1.0.29
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 +3 -4
- package/package.json +1 -1
- package/src/index.ts +4 -5
package/dist/index.js
CHANGED
|
@@ -131,7 +131,7 @@ async function loadRegistries(proxyConfigPath = './.registry-proxy.yml', localYa
|
|
|
131
131
|
export async function startProxyServer(proxyConfigPath, localYarnConfigPath, globalYarnConfigPath, port = 0) {
|
|
132
132
|
const proxyConfig = await loadProxyConfig(proxyConfigPath);
|
|
133
133
|
const registries = await loadRegistries(proxyConfigPath, localYarnConfigPath, globalYarnConfigPath);
|
|
134
|
-
const basePathPrefixedWithSlash = proxyConfig.basePath
|
|
134
|
+
const basePathPrefixedWithSlash = removeEndingSlashAndForceStartingSlash(proxyConfig.basePath);
|
|
135
135
|
console.log('Active registries:', registries.map(r => r.url));
|
|
136
136
|
console.log('Proxy base path:', basePathPrefixedWithSlash);
|
|
137
137
|
console.log('HTTPS:', !!proxyConfig.https);
|
|
@@ -143,14 +143,13 @@ export async function startProxyServer(proxyConfigPath, localYarnConfigPath, glo
|
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
const fullUrl = new URL(req.url, `${proxyConfig.https ? 'https' : 'http'}://${req.headers.host}`);
|
|
146
|
+
console.log(`Proxy server received request on ${fullUrl.toString()}`);
|
|
146
147
|
if (!fullUrl.pathname.startsWith(basePathPrefixedWithSlash)) {
|
|
147
148
|
console.error(`Path ${fullUrl.pathname} does not match basePath ${basePathPrefixedWithSlash}`);
|
|
148
149
|
res.writeHead(404).end('Not Found');
|
|
149
150
|
return;
|
|
150
151
|
}
|
|
151
|
-
const relativePathPrefixedWithSlash = basePathPrefixedWithSlash
|
|
152
|
-
? fullUrl.pathname.slice(basePathPrefixedWithSlash.length)
|
|
153
|
-
: fullUrl.pathname;
|
|
152
|
+
const relativePathPrefixedWithSlash = basePathPrefixedWithSlash === '/' ? fullUrl.pathname : fullUrl.pathname.slice(basePathPrefixedWithSlash.length);
|
|
154
153
|
console.log(`Proxying: ${relativePathPrefixedWithSlash}`);
|
|
155
154
|
const fetchPromises = registries.map(async ({ url, token }) => {
|
|
156
155
|
await limiter.acquire();
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -74,7 +74,7 @@ class ConcurrencyLimiter {
|
|
|
74
74
|
|
|
75
75
|
const limiter = new ConcurrencyLimiter(3);
|
|
76
76
|
|
|
77
|
-
function removeEndingSlashAndForceStartingSlash(str: string): string {
|
|
77
|
+
function removeEndingSlashAndForceStartingSlash(str: string | undefined | null): string {
|
|
78
78
|
if (!str) return '/';
|
|
79
79
|
let trimmed = str.trim();
|
|
80
80
|
if (trimmed === '/') return '/';
|
|
@@ -180,7 +180,7 @@ export async function startProxyServer(
|
|
|
180
180
|
): Promise<HttpServer | HttpsServer> {
|
|
181
181
|
const proxyConfig = await loadProxyConfig(proxyConfigPath);
|
|
182
182
|
const registries = await loadRegistries(proxyConfigPath, localYarnConfigPath, globalYarnConfigPath);
|
|
183
|
-
const basePathPrefixedWithSlash: string = proxyConfig.basePath
|
|
183
|
+
const basePathPrefixedWithSlash: string = removeEndingSlashAndForceStartingSlash(proxyConfig.basePath);
|
|
184
184
|
|
|
185
185
|
console.log('Active registries:', registries.map(r => r.url));
|
|
186
186
|
console.log('Proxy base path:', basePathPrefixedWithSlash);
|
|
@@ -196,15 +196,14 @@ export async function startProxyServer(
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
const fullUrl = new URL(req.url, `${proxyConfig.https ? 'https' : 'http'}://${req.headers.host}`);
|
|
199
|
+
console.log(`Proxy server received request on ${fullUrl.toString()}`)
|
|
199
200
|
if (!fullUrl.pathname.startsWith(basePathPrefixedWithSlash)) {
|
|
200
201
|
console.error(`Path ${fullUrl.pathname} does not match basePath ${basePathPrefixedWithSlash}`);
|
|
201
202
|
res.writeHead(404).end('Not Found');
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
const relativePathPrefixedWithSlash = basePathPrefixedWithSlash
|
|
206
|
-
? fullUrl.pathname.slice(basePathPrefixedWithSlash.length)
|
|
207
|
-
: fullUrl.pathname;
|
|
206
|
+
const relativePathPrefixedWithSlash = basePathPrefixedWithSlash === '/' ? fullUrl.pathname : fullUrl.pathname.slice(basePathPrefixedWithSlash.length);
|
|
208
207
|
console.log(`Proxying: ${relativePathPrefixedWithSlash}`);
|
|
209
208
|
|
|
210
209
|
const fetchPromises = registries.map(async ({url, token}) => {
|