Can you help me out finding the issue? This is the link, and it is running. As described on the tittle, I think my app isworking as expected, but I can’t pass any test from freecodecamp, expect the first one that says “You should provide your own project, not the example URL.”
The first argument for dns.lookup must only be the domain name:
const REPLACE_REGEX = /^https?:\/\//i;
console.log("ANDA POR FAVOR" + req.body.urlToBeShortened)
req.body.urlToBeShortened = req.body.urlToBeShortened.replace(REPLACE_REGEX, '');
//Check if it is a valid URL
dns.lookup(req.body.urlToBeShortened, function(err, addresses) {
I see this error, when I try to submit your code:
POST https://boilerplate-project-urlshortener-2--duke33.repl.co/api/shorturl/new/ 500
eval @ VM50:5
frame-runner.js:98 Error: 500
at eval (eval at <anonymous>
This shows there is an issue with the app crashing. I would expect your Replit terminal to show more errors.
I highly recommend you make use of a .env file to store your DB URI. Anyone can find and take your URI, now, and abuse your database account - not so much a big deal on a free account, but, if you one-day forgot, and connected your credit/debit card to it, then you could be charged a ridiculous amount of money for someone else using it. Also, do not even get me started on the fact that someone could use your DB for malicious/illegal purposes, and you would get the blame.
Well, the thing is that I don’t see any error output when I try the app with, for instance, https://www.freecodecamp.org as the url to be shortened!
The regex will trim it, so, DNS lookup would get www.freecodecamp.org, and the method handles it, I don’t know if I should trim the subdomain, but the thing is that it works, at least on my tests!
This is the output error that I get when run fcc tests:
node v12.16.1
TypeError: Cannot read property 'replace' of undefined
at create_url_record_on_DB (/home/runner/boilerplate-project-urlshortener-2/server.js:50:89)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at next (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:335:12)
at next (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:275:10)
at cors (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:188:7)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:224:17
at originCallback (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:214:15)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:219:13
at optionsCallback (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:199:9)
at corsMiddleware (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:204:7)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:317:13)
TypeError: Cannot read property 'replace' of undefined
at create_url_record_on_DB (/home/runner/boilerplate-project-urlshortener-2/server.js:50:89)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at next (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:335:12)
at next (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:275:10)
at cors (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:188:7)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:224:17
at originCallback (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:214:15)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:219:13
at optionsCallback (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:199:9)
at corsMiddleware (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:204:7)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:317:13)
TypeError: Cannot read property 'replace' of undefined
at create_url_record_on_DB (/home/runner/boilerplate-project-urlshortener-2/server.js:50:89)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at next (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:335:12)
at next (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:275:10)
at cors (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:188:7)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:224:17
at originCallback (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:214:15)
at /home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:219:13
at optionsCallback (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:199:9)
at corsMiddleware (/home/runner/boilerplate-project-urlshortener-2/node_modules/cors/lib/index.js:204:7)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/runner/boilerplate-project-urlshortener-2/node_modules/express/lib/router/index.js:317:13)