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

Is it possible to pass query string in url target? #1323

Closed
leobaiano opened this issue Feb 25, 2019 · 4 comments
Closed

Is it possible to pass query string in url target? #1323

leobaiano opened this issue Feb 25, 2019 · 4 comments

Comments

@leobaiano
Copy link

leobaiano commented Feb 25, 2019

I mounted the https server with the following structure

const target = 'https://test.com/';
const params = '?s=test';
const server = https.createServer (options, function (req, res) {
     proxy.web (req, res, {
         target: target + params,
         secure: false,
         ws: false,
         prependPath: false,
         ignorePath: false,
         changeOrigin: true,
     });
});

The https://test.com page is normally loaded in my localhost reverse proxy but ignores the parameters passed via query string ?=test. How could I do to pass parameters in the target?

@valecarlos
Copy link

did you have any luck?

@leobaiano
Copy link
Author

@valecarlos Not until now :(

@jmaguirrei
Copy link

I came to the same problem, what I did is to override the req.url, like this

import https from 'https';
// import url from 'url';
import path from 'path';
import fs from 'fs';
import httpProxy from 'http-proxy';

import getEnv from '@root/env';
import resolveTarget from './resolveTarget';

const env = getEnv(path);

/* eslint-disable no-sync */
const credentials = {
  key: fs.readFileSync(path.join(__dirname, './certs/server.key')),
  cert: fs.readFileSync(path.join(__dirname,'./certs/server.crt')),
};

const proxyServer = httpProxy.createProxyServer();

proxyServer.on('proxyError', error => {
  console.log('PROXY error: ------------------------------------->', error);
});

const server = https.createServer(credentials, (req, res) => {

  const target = resolveTarget({ req, env });
  const query = '?company_id=co001';
  const fillLength = 50 - req.url.length;
  req.url = `${req.url}${query}`;
  console.log(req.url, '-'.repeat(fillLength), '> target: ', target);
  proxyServer.web(req, res, { target });

}, error => {
  console.log('ERROR ------------------------------->', error);
});


server.listen(env.proxy.httpPort);

console.log(`PROXY listening on port ${env.proxy.httpPort}`);

I hope that helps.

@leobaiano
Copy link
Author

I managed to get to this solution but in the end my problem got knocked up being with the hash of kibana :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants