one of my route is never visited if i run the tests:
app.get("/api/shorturl/:id", async (req, res) => {
let id = req.params.id
console.log(`42: id = ${id}`);
let url = await urlModel.findOne({ short_url: id })
console.log(`44: id = ${id} = url.original_url = ${url.original_url}`);
//res.redirect(url.original_url)
res.json(url); // JSON response with original_url and short_url
})
i have deleted most in my index.js in last minutes (if route not woks i not need anything else. therfore i delete everything first and try find the route with sended data first)
but created a backup to index backup.js
That means something must have interfered with the proper execution (in the index I’ve been using till today, around 7pm Europe time).
the index that i have used the last 2 days with the same rout gets my
a empty object with same source (at this route).
but in my last index there was/is much stuff into . about 400 lines of code. some side-effect maybe. or i dont know. i need find out or need to programing it completely fresh (maybe not bad idea)
index old (last 2 day or so get my no data) near line 150:
app.get("/api/shorturl/:id", async (req, res) => {
let id = req.params.id;
index new (today evening) near line 20 that gives me data:
app.post("/api/shorturl/id", async (req, res) => {
let id = req.body.id;
that was the moment i created many routes to try to get some data from somewhere
Btw there was strange behavior today. website was reloading very often. and was not easy to edit (this maybe happens using large files). BTW i closed some clipboard apps at my Desktop like AutoKey-App. Seems helps a bit.
i got a get result, that looks like it was sendet to my scritpt to my script to itself:
npm run start
> shorturl@0.0.3 start
> node index.js
Listening on port 3000
....
/‾‾‾ req.params object‾‾‾‾‾‾‾‾‾ 35
{ id: 'dummy' }
\___ req.params _________ 35
not falid .... EndOf 79
not valid = .... 26
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:393:5)
at ServerResponse.setHeader (node:_http_outgoing:644:11)
at ServerResponse.header (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/response.js:794:10)
at ServerResponse.send (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/response.js:174:12)
at ServerResponse.json (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/response.js:278:15)
at /home/runner/boilerplate-project-urlshortener/index.js:31:9
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/router/layer.js:95:5)
at next (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/runner/boilerplate-project-urlshortener/node_modules/express/lib/router/layer.js:95:5)
i not test myself. i mean the tests from https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice
I didn’t know that data from myself might come to my script from another source (apart from my index.html or so).
it still the same (as from top of this postings) replit boilerplate-project-urlshortener - Replit
The challenge is to short urls and get the short urls back if it will be asked for.
But now… Whey this error is now not there anymore? i checked it seconds before i pressed the send button… only to be sure. => This error not exist anymore. This is strange. fingerscrossed. I’m feeling a bit like in the movie “Groundhog Day” right now There seems to be a big time lag. Updates come into effect very late.