2

Goal : Connect to a public facing mongodb instance in my local development environment, which is connected to my corporate network.

Background : There is a proxy available for bypassing this corporate firewall. I am developing a Next JS application with mongo as the backend.

Ask : How do I use this proxy to connect to the mongo instance in my node js application?

 const db = await mongoose
      .connect(process.env.NEXT_PUBLIC_MONGO_URI, {
        dbName: "cusum",
        useCreateIndex: true,
        useFindAndModify: false,
        useNewUrlParser: true,
        useUnifiedTopology: true,
      })
      .catch((err) => console.log(err.reason));

This is how I connect to my mongo db instance using mongoose, in my node js application. It works when not connected to my corporate network, but times out when connected to my corporate network.

I was able to connect to the instance using Studio 3T with its built in proxy support, however this is just a GUI client for mongo db.

Attempts

I have attempted to use the global-tunnel package to route all http connections to the proxy but it didn't work.

globalTunnel.initialize({
  host: "proxy-xx.xxx.com",
  port: 8080,
  protocol: "http:",
  connect: "both",
});
zhenming91
  • 21
  • 1
  • 3

1 Answers1

0

I hope this link can help on a corporate proxy issue

Connect to MongoDB database using mongoose behind a proxy

Also, you can look into Nginx as a proxy, depending on your company configuration, though I see you're working wit Nextjs, most of it will depend on the configuration used at your company

Ezekiel
  • 671
  • 5
  • 13