Instantly share code, notes, and snippets.

Embed
What would you like to do?
https with Ionic
var fs = require('fs');
var httpProxy = require('http-proxy');
var http = require('http');
var https = require('https');
var express = require('express');
var app = express();
app.use(function (req, res, next) {
console.log(req);
if (req.url === '/') {
console.log("Transforming response");
var _write = res.write;
// Rewrite the livereload port with our secure one
res.write = function (data) {
_write.call(res, data.toString().replace('35729', '35700'), 'utf8');
}
}
proxy.web(req, res);
}
);
// Proxy fpr connect server to use
var proxy = httpProxy.createServer({
target: {
host: 'localhost',
port: 8100
}
});
//https://matoski.com/article/node-express-generate-ssl/
var secureServer = https.createServer({
key: fs.readFileSync('./server.key'),
cert: fs.readFileSync('./server.crt'),
ca: fs.readFileSync('./ca.crt'),
requestCert: true,
rejectUnauthorized: false
}, app).listen('8101', function() {
console.log('Secure Express server listening on port 8101');
});
@stevethecollier

This comment has been minimized.

Copy link

stevethecollier commented Feb 3, 2016

so were you able to run an ionic app on a device with this?

@inzi

This comment has been minimized.

Copy link

inzi commented May 5, 2016

How did you run ionic serve to point to your ssl?

@rainmak33r

This comment has been minimized.

Copy link

rainmak33r commented Jan 18, 2017

Any idea how to run it on an actual app ?

@ronaiza-cardoso

This comment has been minimized.

Copy link

ronaiza-cardoso commented Jul 27, 2017

@jedininjaster, @inzi and @rainmak33r run the ionic serve normally and then run the proxy and go to the https://localhost:8101 address,. Your application will be there.

@ronaiza-cardoso

This comment has been minimized.

Copy link

ronaiza-cardoso commented Jul 27, 2017

Thank you @justindmyers, your code help me a lot!

@suarezgl

This comment has been minimized.

Copy link

suarezgl commented Nov 2, 2017

Sorry! i don't make this work @ronaiza-cardoso Error: listen EADDRINUSE :::8101 i run ionic serve then run proxy, any solution ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment