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;
next();
} catch (err) {
res.status(400);
}
} 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;
Answers
-
@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
0
Categories
- All Categories
- 176 LFX Mentorship
- 176 LFX Mentorship: Linux Kernel
- 750 Linux Foundation IT Professional Programs
- 373 Cloud Engineer IT Professional Program
- 169 Advanced Cloud Engineer IT Professional Program
- 74 DevOps IT Professional Program - Discontinued
- 4 DevOps & GitOps IT Professional Program
- 99 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 1 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 3 Cloud & Containers Training
- 1 Cybersecurity Training
- 1 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 1 Open Source Best Practice Training
- 1 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 106 Mobile Computing
- 18 Android
- 73 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 950 Programming and Development
- 310 Kernel Development
- 622 Software Development
- 982 Software
- 374 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)
