Comments (8)
Hi @RackerJack
Yes your select is wrong.
This example may help.
https://github.com/No9/harmon/blob/master/examples/rotate.js#L9
Here it is selecting the tag in the HTML and inserting additional HTML
from harmon.
hi
thanks for getting back to me i have tried this but still getting no transformation
var https = require('https'),
http = require('http'),
util = require('util'),
path = require('path'),
fs = require('fs'),
colors = require('colors'),
httpProxy = require('http-proxy'),
connect = require('connect');
var selects = [];
var simpleselect = {};
simpleselect.query = 'body';
simpleselect.func = function (node) {
var out = '<center>MY TEXT</center></body>';
node.createWriteStream({ outer: true }).end(out)}
selects.push(simpleselect);
var app = connect();
var proxy = httpProxy.createProxyServer({target: 'https://DOMAIN.COM', agent : https.globalAgent, headers:{ host: 'DOMAIN.COM' }}).listen(8011);
app.use(require('harmon')([], selects));
app.use(function(req, res) {
proxy.web(req, res);
});
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8011'.yellow);
from harmon.
Ah I was too busy looking at the selector :)
So you left out attaching the proxy to a webserver and instead just started the proxy with .listen(8011);
I have messed around with the code a bit to get a working version for you so hopefully this will get you on your way
N.B. At the web server at the end of the script.
http.createServer(app).listen(8011);
Also your https mapping solves #22 so thanks for that :)
var https = require('https'),
http = require('http'),
util = require('util'),
path = require('path'),
fs = require('fs'),
colors = require('colors'),
httpProxy = require('http-proxy'),
connect = require('connect');
var selects = [];
var simpleselect = {};
simpleselect.query = 'body';
simpleselect.func = function (node) {
var stm = node.createStream({ outer: true });
stm.on('data', function(data) {
//Dropping the data
})
stm.on('end', function(){
util.puts('fired end'.red);
var out = '<body><center>MY TEXT</center></body>';
stm.end(out);
})
}
selects.push(simpleselect);
var app = connect();
var proxy = httpProxy.createProxyServer({target: 'https://nodejs.org', agent : https.globalAgent, headers:{ host: 'nodejs.org' }});
app.use(require('harmon')([], selects, true));
app.use(function(req, res) {
proxy.web(req, res);
});
http.createServer(app).listen(8011);
util.puts('http proxy server'.blue + ' started '.green.bold + 'on port '.blue + '8011'.yellow);
from harmon.
@No9 still no luck
your example works fine for nodejs.org but not on the site im trying it for
Does harmon have an issue if the backend proxy is gzipped??
from harmon.
Yes it doesn't handle decompression as that should be done by an interceptor either in the request or in the response.
There is an outline of doing it in the request here
#19
using the proxyReq event.
I haven't seen a decompress for connect responses but I haven't really looked that hard
from harmon.
excellent!! thanks for the direction :D
from harmon.
@RackerJack Gzip support and a sample has been added to the repo
https://github.com/No9/harmon/blob/master/examples/gzipped.js
from harmon.
wow thanks for this!!
from harmon.
Related Issues (20)
- how to use harmon on specify url HOT 1
- prepareRequestSelectors HOT 1
- Dealing with bad html HOT 9
- How to use in non-html? HOT 2
- Connection hangs for very generic selectors HOT 6
- doge.js is redirecting to original site with no injection HOT 7
- Request hangs
- gzip content length issue HOT 2
- Proxy a m3u8 file HOT 1
- Variable Targets
- Use with browsersync HOT 2
- js/css filter with query params HOT 2
- Doesn't work nowadays? Examples and tests fail HOT 9
- Replacing the value inside an element HOT 3
- write() getting called before writeHead() on gzip'd content causes failures HOT 2
- help w/ hello world, they don't require harmon? HOT 1
- got error on zlib HOT 1
- No selector callbacks being invoked for certain sites HOT 2
- How to modify a file from a response
- Content Length not deleted on HTML rewrite if HTML Only HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from harmon.