-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxycss.js
More file actions
38 lines (30 loc) · 1.26 KB
/
proxycss.js
File metadata and controls
38 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var http = require('http'), httpProxy = require('http-proxy');
var connect = require('connect');
var fs = require('fs');
var record_dir="www";
httpProxy.createServer(function (req, res, proxy) {
if(req.url.match(/\.css\?*/)){
proxy.proxyRequest(req, res, { host: 'localhost', port: 8000 });
} else {
proxy.proxyRequest(req, res, { host: 'localhost', port: 80 });
var options = { host: 'localhost' , port: 80, path: req.url };
//var options = { host: 'www.google.com' , port: 80 , path: '/images/logos/ps_logo2.png' }
var request = http.get(options, function(r){
var imagedata = ''
r.setEncoding('binary')
r.on('data', function(chunk){ imagedata += chunk })
r.on('end', function(){
fs.writeFile(record_dir+req.url, imagedata, 'binary', function(err){
if (err) throw err;
console.log('File saved.');
})
})
})
}).listen(9000);
////////////////////////////////////////////////////////////////////////////
//////////////////normal http server on port 8000 //////////////////////////
////////////////////////////////////////////////////////////////////////////
connect.createServer(
connect.static("www")
).listen(8000);
////////////////////////////////////////////////////////////////////////////