October 24, 2024
Chicago 12, Melborne City, USA
javascript

Node.js server running on Terminal but not loading on browser


I am trying to achieve a proxy server using node.js where my proxy server is running on the terminal as

Proxy server running on http://0.0.0.0:3000

but over the browser, it’s not working. I am using AWS EC2 and earlier when I faced an issue with Flask App I added custom TCP in AWS -> Security Group -> Inbound rules and it worked however this one is not working with that either. following is the code:

const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');

const app = express();

// Proxy configuration
app.use('/', createProxyMiddleware({
  target: 'https://target-website.com', // Replace with the actual target website URL
  changeOrigin: true,
  selfHandleResponse: true,
  onProxyRes: (proxyRes, req, res) => {
    let body = Buffer.from('');
    proxyRes.on('data', (chunk) => {
      body = Buffer.concat([body, chunk]);
    });
    proxyRes.on('end', () => {
      let content = body.toString();
      
      // Modify the HTML content to autofill and submit the login form
      content = content.replace('</body>', `
        <script>
          document.getElementById('amember-login').value="yourUsername";
          document.getElementById('amember-pass').value="yourPassword";
          document.getElementById('submit').click();
        </script>
      </body>`);

      res.send(content);
    });
  },
}));

// Start the proxy server
app.listen(3000, () => {
  console.log('Proxy server running on http://localhost:3000');
});
`



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video