Skip to content

Commit 996ddd3

Browse files
authored
fix(proxy): clean up proxy path handling and ensure querystrings are preserved (cryostatio#117)
1 parent 7bbda2b commit 996ddd3

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

backend/src/server.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import fs from 'fs';
1919
import * as k8s from '@kubernetes/client-node';
2020
import express from 'express';
2121
import morgan from 'morgan';
22-
import { ParsedQs } from 'qs';
22+
import { ParsedQs, stringify as stringifyQuery } from 'qs';
2323
import { Duplex } from 'stream';
2424

2525
const port = process.env.PORT || 9943;
@@ -219,14 +219,10 @@ app.use('/upstream/*', async (req, res) => {
219219
ssl: tlsOpts,
220220
xfwd: true,
221221
};
222-
let correctedUrl = (req.baseUrl + req.url).replace(/^\/upstream(\.*)/, '');
223-
// normalize
224-
while (correctedUrl.includes('//')) {
225-
correctedUrl = correctedUrl.replace('//', '/');
226-
}
227-
if (correctedUrl.endsWith('/')) {
228-
// trim trailing slash if any
229-
correctedUrl = correctedUrl.substring(0, correctedUrl.length - 1);
222+
const qs = stringifyQuery(req.query);
223+
let correctedUrl = req.baseUrl.replace(/^\/upstream/, '');
224+
if (qs) {
225+
correctedUrl += `?${qs}`;
230226
}
231227
req.url = correctedUrl;
232228
console.log(`Proxying <${ns}, ${name}> ${method} ${req.url} -> ${opts.target}`);

0 commit comments

Comments
 (0)