question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access Through Proxy

See original GitHub issue

Having trouble connecting through a corporate proxy to a host. the http module in node by can connect through a proxy by specifying

{
    host: 'proxy.example.com',
    path: 'http://example.elasticsearch.com'
}

however specifying this in the elasticsearch hosts configurations don’t work as expected.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
clakechcommented, Aug 1, 2016

Maybe this code can help someone.

Add an env variable to reach your proxy HTTP_PROXY = http://127.0.0.1:5000/

const elasticsearch = require('elasticsearch');
const proxy = require('proxy-agent');

const client = new elasticsearch.Client({
  host: 'my.host.com',
  createNodeAgent: () => proxy(process.env.HTTP_PROXY)
});

client.search(query);

Au revoir 😚

2reactions
imran-ukcommented, Feb 8, 2017

@clakech Thanks very much, that worked for us too.

I had to code it slightly differently to cater for the PROXY env var being missing - in whichcase a direct connection is made:

'use strict';

const elastic = require('elasticsearch'),
      proxy = require('proxy-agent'),
      config = require('../../config/config.js');

let nodeAgent;

if(process.env.MY_ELASTIC_PROXY) {
  nodeAgent = () => proxy(process.env.MY_ELASTIC_PROXY);
}

const client = new elastic.Client({
  host:               config.elastic.host,
  log:                config.elastic.log,
  suggestCompression: config.elastic.compression,
  apiVersion:         config.elastic.apiVersion,
  createNodeAgent:    nodeAgent
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

The Fastest Free Proxy | hide.me
Easily access blocked content and websites with our FREE web proxy. Hide your real IP address and encrypt your internet connection to protect...
Read more >
What is a Proxy Server? How does it work? - Fortinet
An anonymous proxy focuses on making internet activity untraceable. It works by accessing the internet on behalf of the user while hiding their...
Read more >
Best Free Proxy in the World | Anonymous Browsing - HMA VPN
Access blocked websites from anywhere in the World with the HMA Free Proxy. The simple way to hide your IP and browse anonymously....
Read more >
How to Set Up a Proxy Server on Your PC, Mac, or Web Browser
To access the Windows Settings menu, press the Windows + I keys simultaneously. · On Windows 10, click Settings > Network & Internet...
Read more >
A Beginners Guide to Proxy Servers and VPNs
To access a VPN gateway or server from a device e.g. computer or mobile phone you need VPN software installed on that device....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found