This is for the course section: Back End Development and APIs > Basic Node and Express > Implement a Root-Level Request Logger Middleware
I couldn’t get the test to pass: “Root level logger middleware should be active”. I tried several different methods to achieve the required string format. I tried several different ways to set the middleware at root for all requests (e.g. app.use(), app.get(), app.use([function-only]), app.use(“/*”, [function])). I knew I was meeting the requirements to pass and I finally found the bug in the course tests when I switched to the Google Chrome browser - it displayed this log:
After this I was able to grep through the code base to find the module that tests for the correct user submitted conditions. I found this RegEx in wrappers.js
in the fcc-express-background
module under node_modules
.:
/(GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE)\s\/.*\s\-\s.*(\d{1,3}\.){3}\d{1,3}/
The front half of the RegEx is great, it’s the part on the end that is matching the IP. It’s only looking for IPv4-style addresses (e.g. 123.456.789.012). However, as you can see in my screenshot above, my local browser’s IPs are coming through as ::1
. I modified the RegEx to allow for this IPv6 localhost IP, and the test passed straight away.
This is a fairly wide-spread issue:
https://forum.freecodecamp.org/search?q=Root%20level%20logger%20middleware%20should%20be%20active
I hope that helps. I thought about submitting a pull request for the course repo but I just don’t know enough to be able to do that at this point.
Feel free to email me with any questions.