Giter Site home page Giter Site logo

am i doing this right? about harmon HOT 8 CLOSED

no9 avatar no9 commented on July 23, 2024
am i doing this right?

from harmon.

Comments (8)

No9 avatar No9 commented on July 23, 2024

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.

hijak avatar hijak commented on July 23, 2024

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.

No9 avatar No9 commented on July 23, 2024

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.

hijak avatar hijak commented on July 23, 2024

@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.

No9 avatar No9 commented on July 23, 2024

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.

hijak avatar hijak commented on July 23, 2024

excellent!! thanks for the direction :D

from harmon.

No9 avatar No9 commented on July 23, 2024

@RackerJack Gzip support and a sample has been added to the repo
https://github.com/No9/harmon/blob/master/examples/gzipped.js

from harmon.

hijak avatar hijak commented on July 23, 2024

wow thanks for this!!

from harmon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.