Skip to content

How to set proxy #87

@shanmugharajk

Description

@shanmugharajk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions