I'm making a web proxy in express.js, and I'm trying to make functionality for the server to allow requests for opening webpages to go through. This is what I have so far:const express = require('express'); const app = express(); app.get('/', function(req, res) { console.log(req.hostname); if(req.method === 'GET') { res.redirect(302, req.originalUrl); } }); app.listen(8080, () => console.log("Listening on port 8080")); I intended for this code to receive a request to open a webpage while the user is using a web browser, print out the hostname, then let the browser connect to the webpage and display it. After the redirect line executes, the redirect causes my code to start again. It's an infinite loop, causing the browser to never be able to connect to and display a webpage. I may have run into this problem due to a lack of knowledge about networks. How do I fix this bug?
Submitted May 09, 2020 at 08:01PM by geetar123
No comments:
Post a Comment