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

How to set proxy #87

Open
shanmugharajk opened this issue May 8, 2024 · 0 comments
Open

How to set proxy #87

shanmugharajk opened this issue May 8, 2024 · 0 comments

Comments

@shanmugharajk
Copy link

shanmugharajk commented May 8, 2024

I've set HTTP_PROXY, HTTPS_PROXY. I verified the connectivity using curl in the machine which I tried this library. curl, node's native fetch works fine and pushes the logs. Only this library gives error with proxy. The code snippets which I tried are below,

fetch example

import proxy from "undici";

const proxyUrl = new URL("proxy url");

const agent = new proxy.ProxyAgent({
  uri: proxyUrl.protocol + proxyUrl.host,
});

fetch(
  "https://domain:443/services/collector/event/1.0",
  {
    dispatcher: agent,
    method: "POST",
    body: '{}',
    headers: {
      "Content-type": "application/json; charset=UTF-8",
      authorization: "Splunk token",
    },
  }
)
  .then((res) => {
    console.log("== res", res.statusText);
  })
  .catch((e) => {
    console.log("== err", e);
  });

This is working.

splunk-logging example

import splunk from "splunk-logging";

let token = "";
let index = "";

let logger = new splunk.Logger({
  port: 443,
  token,
  url: "",
});

logger.send(
  {
    message: {
      message: "",
      timestamp: new Date(),
    },
    severity: "error",
    metadata: {
      source: "",
      sourcetype: "",
      index
    },
  },
  (error, req, res) => {
    console.log(error);
    console.log(res);
  }
);

This throws an error ERROR: Error: connect ENETUNREACH

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

1 participant