Sunday, 14 May 2017

HTTPS server not working on Android mobile phone but HTTP does?

I am currently learning how to create servers with Node js and other Javascript apis, and I've built a both HTTP and HTTPS server which works fine on every pc navigator of my nat network but when I try the https server on my android mobile device with: https://192.168.1.20:8443 which is where I built my node.js server it won't load and say the page is not working although it works with http.

I would also like to know if I could make my server visible or access to it with my router public ip address and how could I do that.

This is my server code:

var fs = require('fs');
var http = require('http');
var https = require('https');
var cors = require('cors');
var privateKey  = fs.readFileSync('host.key', 'utf8');
var certificate = fs.readFileSync('host.cert', 'utf8');

var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
app.use(cors());
app.use('/work', express.static('/.'))
app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
    console.log('Servidor en marxa.');
});


var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);

httpServer.listen(8080);
httpsServer.listen(8443);



via maga

No comments:

Post a Comment