Search code examples
node.jsproxyserverappjs

How to configure AppJS to work with node-http-proxy server


I'm trying to get node-http-proxy working with AppJS. Unfortanly it crashes on launch of the app. What I did:

  • Download & extracted AppJS from http://appjs.com/;
  • Installed node-http-proxy with npm install http-proxy;
  • Edited the app.js window.on(create) function:

    window.on('create', function(){
    console.log("Window Created");
    window.frame.show();
    window.frame.center();
    window.frame.setMenuBar(menubar);
    
    var http = require('http'),
    httpProxy = require('http-proxy');
    // 
    // Create your proxy server and set the target in the options. 
    // 
    httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
    
    // 
    // Create your target server 
    // 
    http.createServer(function (req, res) {
      res.writeHead(200, { 'Content-Type': 'text/plain' });
      res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
      res.end();
    }).listen(9000);
    });
    

When the app starts I want to start the nodeJS proxy server. Is it possible to connect from a external PC to this proxy server? (I know I will need to open ports for this)

For example if I run the app on my home PC and at work I will set the proxy settings of the work PC to homePC_IP:8000. Will this work?


Solution

  • Haven't got a fix for the crash of node-http-proxy but I instead I used https://github.com/TooTallNate/proxy and this works like a charm!