Urlshortener works for posting and redirect, but not passing tests

After a very frustrating start, I have code that works when I test it on my browser, but will not pass the second or third test. I have not addressed the issue with a unique shortUrl for each record yet, but I can fix that later. I’m wondering if someone can point me in the right direction for getting my functioning code to pass the first three tests!

Your project link(s)

solution: https://replit.com/@carolmurphy/boilerplate-project-urlshortener-2

Your browser information:

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

Challenge: URL Shortener Microservice

Link to the challenge:

It’s a CORS error. From my browser console:

Access to fetch at 'https://boilerplate-project-urlshortener-2.carolmurphy.repl.co/api/shorturl' from origin 'https://www.freecodecamp.org' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

You need to tell CORS to let other hosts have access here:

app.use(cors());

Your verification stuff won’t work either looking for www or http://www in valid URLs as the tests will use https://boilerplate-project-urlshortener-2.carolmurphy.repl.co/ plus some parameters to test which is valid and does not contain www or http://www.

Thanks, jeremy. I woulda swore I had that in there. I think I’ll switch to validation for my url verification method instead of dns. once I get things more squared away. This process has been a steep learning slope for me. Once I get down a rabbithole, I get so confused I just start throwing code into the mix and it gets so muddled I do better scrapping it and starting over from scratch! I think I’m close to having a working solution that I will actually understand pretty well.

It works! I switched to validator and scrapped dns, then worked in an way to make the shorturl unique, and I passed!
Thanks for your clue.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.