0
I have a service on Nodejs that does a fetch to access an external api:
const express = require('express');
const middlewares = require('./middlewares/middlewares');
const routes = require('./routes');
const raven = require('raven');
const config = require('./config');
const mongoose = require('mongoose');
const winston = require('winston');
const fetch = require('node-fetch');
const logger = winston.createLogger({
transports: [
new winston.transports.Console()
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.json()
)
});
if (config.MONGO_CONNECTION_URL !== undefined) {
mongoose.connect(config.MONGO_CONNECTION_URL, { useNewUrlParser: true });
const app = express();
middlewares(app);
app.use('/', routes);
fetch('https://my-json-server.typicode.com/giuliana-bezerra/demo/comments').then(console.log);
const startServer = (port = 7755) => {
const server = app.listen(port, function () {
raven.config(config.LOG_SENTRY_DSN).install();
logger.info(`server.settingsservice.initilization.running.${server.address().port}`);
});
};
module.exports = startServer;
} else {
logger.error(`server.settingsservice.initilization.database.notFound`);
process.exit(0);
}
The problem is that I use a corporate proxy, and so fetch is waiting indefinitely.
How do I set up, preferably globally, my proxy to be used in the external Apis calls within the nodejs? I’ve done a lot of research, but the solutions offered are proxy configuration for the Node service itself, not for calls to Apis by the service.
Very good! Works for a call within my service. But what about the library calls I use on my service? (e.g. multer-Storage-cloudinary). I could not modify the libs code to use this module. There is no global way to configure this for the nodejs?
– Giuliana Bezerra
@Giulianabezerra worse than in this case does not work. I would look at the library documentation, but I just checked and this example you used has no mention of
proxy
– Sorack
Got it, thanks for the help. I’ll mark your answer there, as it answers to the example I put in the question.
– Giuliana Bezerra