Wednesday, 15 March 2017

Local node.js server GET error when trying to load an HTML file

Quite new to this. I have the below node sever that runs locally on my machine. In index.html page I made a XMLHttpRequest to some web API, and my browser will be redirected to a url that starts with 10.200.100.200:8080/auth(suppose 10.200.100.200 is my IP)

The problem is that, currently a GET request to http://10.200.100.200:8080/auth returns an empty response. It doesn't work either when I paste that url to browser. What am I doing wrong with that node server? The index page seems to be working ok. Many thanks for your help!

node server:

 var fs = require('fs');
 var http = require('http');
 var https = require('https');
 var request = require('request');
 var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
 var path = require('path');
 var express = require('express');
 var app = express();
 var certificate = fs.readFileSync( 'something.0.0.1.cert' );
 var privateKey  = fs.readFileSync('something.0.0.1.key');

 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
 app.use(express.static(__dirname+'/public'));

 app.get('/auth', function(req, res) {
    res.sendFile(path.join(__dirname + '/public'+ '/html'+'/authCode.html'));   
});

 app.get('/', function (req, res) {
    res.sendFile(path.join(__dirname + '/public'+ '/html'+'/index.html')); 
 });



https.createServer({
  key: privateKey,
  cert: certificate
}, app).listen(8080,'0.0.0.0');



via user4046073

No comments:

Post a Comment