问题
It seems like all outbound requests (e.g. http.request(…), restify.post(…)) send to an https:// URL are being converted to http:// for some reason (OpenShift proxying?). How can I call an external API and make sure I hit the HTTPS URL instead of the HTTP one?
Here's a concrete example. This call to the StubHub API works perfectly when I run it from localhost, but as soon as I run it in an OpenShift or Heroku NodeJS container/dyno, I get forced to http://api.stubhub.com/ and accordingly get an error.
var express = require('express'),
server = express(),
fetch = require('node-fetch')
qs = require('qs');
// api
var api = express.Router();
server.use('/api/v1', api);
api.post('/login', function (req, res) {
fetch('https://api.stubhub.com/login', {
method: 'POST',
headers: {
Authorization: 'Basic <TOKEN>',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: qs.stringify({
grant_type: 'password',
username: req.query.username,
password: req.query.password,
scope: 'PRODUCTION',
}),
})
.then(function (response) {
res.send(response.json());
});
});
// server
server.listen(process.env.NODE_PORT || 3030, process.env.NODE_IP || 'localhost');
来源:https://stackoverflow.com/questions/36142296/send-an-outbound-post-request-using-https-on-openshift-heroku