From 27be959cf8406bb14c5c5cc40bf04adaeb440239 Mon Sep 17 00:00:00 2001 From: limbo <43649186+HUAHUAI23@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:15:00 +0800 Subject: [PATCH] fix(runtime): fix storage server query url problem (#1910) fix(runtime): fix storage server query url problem (#1910) --------- Co-authored-by: HUAHUAI23 --- runtimes/nodejs/src/storage-server.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/runtimes/nodejs/src/storage-server.ts b/runtimes/nodejs/src/storage-server.ts index 828b319369..6d764a2b16 100644 --- a/runtimes/nodejs/src/storage-server.ts +++ b/runtimes/nodejs/src/storage-server.ts @@ -27,12 +27,14 @@ const websiteHostingPathHandler = async ( } const minioUrl = new URL(url, Config.OSS_INTERNAL_ENDPOINT) - const paths = tryPath(websiteHosting.bucketName, url) + + const paths = tryPath(websiteHosting.bucketName, minioUrl.pathname) for (const path of paths) { minioUrl.pathname = path try { await axios.head(minioUrl.toString()) + // Url.pathname only contain path eg: /path , Url.search only contain query string eg: ?query=string return minioUrl.pathname + minioUrl.search } catch (err) { if ((err as AxiosError).response?.status !== 404) { @@ -40,7 +42,7 @@ const websiteHostingPathHandler = async ( } } } - return url // If all paths are unavailable, the original URL is returned. + return url // If all paths are unavailable, the original url string is returned. } const storageServer = http.createServer( @@ -57,16 +59,21 @@ const storageServer = http.createServer( res.end() return } + try { const proxyReqUrl = new URL(Config.OSS_INTERNAL_ENDPOINT) - const path = await websiteHostingPathHandler(req.headers.host, req.url) + + const path = await websiteHostingPathHandler( + req.headers.host || '', + req.url || '', + ) const proxyReq = http.request({ host: proxyReqUrl.hostname, port: proxyReqUrl.port, headers: req.headers, method: req.method, - path: path, + path: path, // contain query string eg: /path?query=string }) proxyReq.on('response', (proxyRes: http.IncomingMessage) => {