Bug in testing for Advanced Node and Express - Set up the Environment?

I have been having trouble getting the tests to pass for instantiating socket.io and having the client connect to the server. But, I had followed all of the instructions on the page correctly (and really, these instructions are pretty straightforward). I found a problem with the fcctesting.js file, despite the comment specifically asking not to edit this file.

In fcctesting.js, there is a middleware function to set the Access-Control-Allow-Origin depending on an array of potential origin urls. In the allowedOrigins array we have ‘https://freecodecamp.com’, ‘https://beta.freecodecamp.com’, ‘http://freecodecamp.com’, ‘http://beta.freecodecamp.com’, among others.

However, the tests are coming from the origin ‘https://www.freecodecamp.org’ (not .com), and that origin is not in the array. I had to add it to the array to get the test to pass. I think this needs to be added in the boilerplate source so that we can pass the tests while leaving fcctesting.js unmodified.

Your code so far

app.use(function (req, res, next) {
      var allowedOrigins = [/* I had to add this myself -->  */ 'https://www.freecodecamp.org', /* <--it wasn't in the original array*/ 'https://pricey-hugger.gomix.me', 'http://pricey-hugger.gomix.me', 'https://freecodecamp.com', 'https://beta.freecodecamp.com', 'http://freecodecamp.com', 'http://beta.freecodecamp.com','http://localhost:3000', 'https://localhost:3000']
       var origin = req.headers.origin;
        if(allowedOrigins.indexOf(origin) > -1){
             res.setHeader('Access-Control-Allow-Origin', origin);
      //res.setHeader('Access-Control-Allow-Origin', 'https://pricey-hugger.gomix.me');
      res.setHeader('Access-Control-Allow-Credentials', true);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Set up the Environment

Link to the challenge:

1 Like

Thank you very much ! It solved if for me.