node.js - Making requests to a node API from a different domain using HTTPS -


i serving static page on https (https://example.com) makes requests node api on different domain (example-api.com).

my api standard express app using http. here's setup code:

var express = require('express'); var app = exports.app = express(); var port = process.env.port;  exports.server = require('http').createserver(app).listen(port); 

in requests static page, specify https://example-api.com url. works of time, every once in while (10% of time?) chrome errors out on requests with:

net::error_insecure_response 

other users who've come across issue (e.g. failed load resource: net::err_insecure_response socket.io) seem solve adding credentials option createserver call, e.g.

var server = https.createserver(credentials, app) 

so when tried implement came following:

var fs = require('fs'); var options = {   key: fs.readfilesync('server-key.pem'),   cert: fs.readfilesync('server-cert.pem') }; var express = require('express'); var app = exports.app = express();  exports.server = require('https').createserver(options, app).listen(port); 

however solution doesn't seem work me. when try requests never make app - logs in app.use middleware don't appear.

what's confusing fact setup seems work of time.

does know how can reliably make requests?

thanks , sorry in advance ignorance.

i struggled bit well. if on windows have solution bit of work around, allow serve site, , nodejs app on https.

in windows, created reverse proxy in iis point @ nodejs restful endpoint (i.e. nodejs restful services == website.com:7000). don't let reverse proxy scare you, gravy.

to implement:

  1. install iis (if haven't already)
  2. create self signed cert (assuming know how that), or apply cert using now.
  3. install application request routing
  4. open website configuration, , go url rewrite
  5. for rewrite stuff:

for pattern: ^api(.*)

for rewrite: http://www.website.com:7000{r:1}

this takes request from: https://www.website.com/api/someapiawesomeness, , rewrites nodejs app running @ http://www.website.com:7000. have ssl restful app..

good luck man hope helps!


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -