Welcome to the Linux Foundation Forum!

Lab 8.1 - Validation.js issue - returning false negative


Hi @davidmarkclements , Hi all,

I am encountering validation issue when running node validate.js

It returns

PS D :\LinuxFoundation\LFW212\Lab8.1> node .\validate.js
☑️ GET http://localhost:3011/bad-route responded with 404 response
☑️ GET http://localhost:3011/ responded with 400
☑️ GET http://localhost:3011/?url=http://localhost:7686/bad-route responded with 404 response
⛔️ GET http://localhost:3011/?url=http://localhost:7686/redir must forward 301 response from upstream server, got 404

It says, my app doesn't forward 301.

To test this, I created a server that will return me 301 response, running on http://localhost:6000/redir

Then I hit my app with query ?url=http://localhost:6000/redir

It looks fine on Postman

I did the same using chrome browser, and it returns me the same result as Postman (301 response)

I wonder, is there any issue with the validation.js file for Lab 8.1? I am using the newest 2023 version.

My codes looks like this (using Express)

var express = require("express");
var router = express.Router();
var createError = require("http-errors");
const { createProxyMiddleware } = require("http-proxy-middleware");

function setProxyTarget(req, res, next) {
  const url = req.query.url;

  if (url) {
    try {
      new URL(url);
      res.locals.url = url;
    } catch (err) {
  } else {
    return next(createError(400));

function proxy(req, res, next) {
  const settingProxy = createProxyMiddleware({
    target: res.locals.url,
    changeOrigin: true,
    logger: console,
    followRedirects: true,

  settingProxy(req, res, next);

router.get("/", setProxyTarget, proxy);

module.exports = router;


  • xdxmxc
    xdxmxc Posts: 148
    edited November 2023

    @jimmycheung22 all the code does is hit the end point and check status code response. What might be happening is connection to a server running old code? Are you manually setting the port? 3011 looks human-set to me - if you are then you're probably just hitting the wrong server or something. Testing against another port endpoint doesn't help confirm/deny any issues - you need to check against the same exact server instance


Upcoming Training