now I have a problem. I use nodejs as a cross-domain proxy server, and the interface address is constantly changing. I hope I can enter the address of the interface on the html page, then read the data of this interface in the server.js file and return it to the html page. How should I write my html page?
< H1 > question 1 < / H1 >
var http = require("http");
var url = require("url");
var qs = require("querystring");
//nodehttp
http.createServer(function(req , res) {
//
res.setHeader("Access-Control-Allow-Origin" , "*");
//
var query = url.parse(req.url).query;
//qs
var queryObj = qs.parse(query);
//myUrl=GET
var myUrl = "http://tianjinshuxie.net/interfaces/abc.php";
//
var data = "";
// http.get()
http.get(myUrl,function (request) {
//myUrl
//
request.setEncoding("utf8");
//data
request.on("data", function (response) {
data += response;
});
//end
request.on("end" , function () {
//data
res.end(data);
});
}).on("error" , function () {
console.log("myUrl");
});
}).listen(8989, function(err){
if(!err){
console.log("8989...");
}
});