Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime): fix storage server query url problem #1910

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading