Skip to content

Commit

Permalink
fix(runtime): fix storage server query url problem (#1910)
Browse files Browse the repository at this point in the history
fix(runtime): fix storage server query url problem (#1910)

---------

Co-authored-by: HUAHUAI23 <lim@outlook.com>
  • Loading branch information
HUAHUAI23 and HUAHUAI23 authored Mar 15, 2024
1 parent 9ec2a97 commit 27be959
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions runtimes/nodejs/src/storage-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ 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) {
break
}
}
}
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(
Expand All @@ -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) => {
Expand Down

0 comments on commit 27be959

Please sign in to comment.