Use the .env File Challenge Issue
See original GitHub issueFor more coverage, I am opening this here:
Challenge: https://www.freecodecamp.org/learn/apis-and-microservices/basic-node-and-express/use-the--env-file
As of <04/02/2021, a change has caused the above mentioned lesson to be uncompletable.
Error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:91:26
The error in full:
Error
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:91:26
at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:33:7)
at IncomingMessage.emit (events.js:315:20)
at IncomingMessage.Readable.read (_stream_readable.js:505:10)
at flow (_stream_readable.js:1005:34)
at resume_ (_stream_readable.js:986:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)
at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:99:28
at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:33:7)
at IncomingMessage.emit (events.js:315:20)
at IncomingMessage.Readable.read (_stream_readable.js:505:10)
at flow (_stream_readable.js:1005:34)
at resume_ (_stream_readable.js:986:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
_http_outgoing.js:518
throw new ERR_HTTP_HEADERS_SENT('set');
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:518:11)
at ServerResponse.header (/home/runner/boilerplate-express-2/node_modules/express/lib/response.js:771:10)
at ServerResponse.send (/home/runner/boilerplate-express-2/node_modules/express/lib/response.js:170:12)
at ServerResponse.json (/home/runner/boilerplate-express-2/node_modules/express/lib/response.js:267:15)
at /home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:108:15
at IncomingMessage.<anonymous> (/home/runner/boilerplate-express-2/node_modules/fcc-express-bground/index.js:33:7)
at IncomingMessage.emit (events.js:315:20)
at IncomingMessage.Readable.read (_stream_readable.js:505:10)
at flow (_stream_readable.js:1005:34)
at resume_ (_stream_readable.js:986:3) {
code: 'ERR_HTTP_HEADERS_SENT'
}
If you encounter this, the best course of action is to skip the lesson, and continue with the curriculum.
As nothing obvious has changed on freeCodeCamp’s side, this is likely an issue on Repl.it’s side.
Current Debugged Steps
- Tested code which previously used to pass - no longer passes
- Downgraded
express
package - no effect - One user was able to pass, and the noticeable difference was their
origin
was notfreecodecamp.org
, when they submitted. - All manor of sending data via stringifying etc.
From forum post: https://forum.freecodecamp.org/t/headers-error-in-env-challenge/444357
_P.S. Even though I have said there has been no change to the challenge, in the last few seconds (19:00 UTC) there has been a change pushed to main
. Otherwise, our side has not changed in a way I can see which would affect this
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:15 (15 by maintainers)
I believe I’ve found what’s happening, although not fully sure why.
Long story short - request send from ie.
/_api/use-env-vars
to the relevant/json
route uses http, what results in (repl.it?) trying to redirect to https. I don’t know how up to date this information is, but I’ve found posts thathttp.request
doesn’t follow redirects on it own.https://github.com/freeCodeCamp/fcc-express-bground-pkg/blob/master/index.js#L16
Taking repl.it as example:
req.host
doesn’t contain port, soport
is undefined and in the request will be always used80
. Second thing is thatprotocol
in passedreq
ishttp
. Changingprot
tohttps
andport
to443
makes everything work.FWIW this is affecting also
Basic Node and Express - Implement a Root-Level Request Logger Middleware
andBasic Node and Express - Chain Middleware to Create a Time Server
.@JoshuaPelealu There is a temporary solution, just waiting to be QAed.