freeCodeCamp and Glitch integration - A possible workaround
Let me guess:
At this point, I also can guess you are struggling with errors such:
OK, say no more. Here's a possible workaround (it worked for me!)
That unexpected token, <, is a strong clue that the response was HTML instead of JSON.
The root cause is that the server returned HTML or some other non-JSON string. Why would it do that?
“Unexpected token o in JSON at position 1” and other varieties
The exact text of this error will differ depending on what the server returned.
The token and the position may vary, but the root cause is the same: the text that your app is trying to parse as JSON is not actually valid JSON.
In my case, I used a simple Node JS + Express server
I won't dig into basic details (there are tons of documentation out there) but I'll highlight the key steps.
The key here use is to use the res.json() function.
Here we go:
This workaround worked for me, and I was able to pass the requested challenges.
PS: You can follow this thread if you wish to have more information from:
freeCodeCamp support: FCC Support
github test repository issues: github issues
Any question or doubt, feel free to ask me in the comments section.
You are having a nightmare trying to make freeCodeCamp + Glitch work together successfully
At this point, I also can guess you are struggling with errors such:
Unexpected token in JSON at position
OK, say no more. Here's a possible workaround (it worked for me!)
The issue
JSON should start with a valid JSON value – an object, array, string, number, or false/true/null. This response started with a < (hence the “Unexpected token <”).That unexpected token, <, is a strong clue that the response was HTML instead of JSON.
The root cause is that the server returned HTML or some other non-JSON string. Why would it do that?
“Unexpected token o in JSON at position 1” and other varieties
The exact text of this error will differ depending on what the server returned.
The token and the position may vary, but the root cause is the same: the text that your app is trying to parse as JSON is not actually valid JSON.
The workaround
You can set up your own server, and provide the requested answer right from your end and not depend on Glitch services.In my case, I used a simple Node JS + Express server
I won't dig into basic details (there are tons of documentation out there) but I'll highlight the key steps.
The key here use is to use the res.json() function.
Here we go:
1.- Create your HTTPS server
var server = https.createServer(options, app);
server.listen(SSL_PORT, function(){
console.log(SERVER_MESSAGE);
});
2.- Create a JSON template
let jsonTpl = `{
"author": "John Doe",
"description": "freeCodeCamp - Apis And Microservices Certification (300 hours)"
}`;
3.- Create the API endpoint
app.get('/_api/package.json',function(req,res){
res.json(jsonTpl);
res.end();
});
This workaround worked for me, and I was able to pass the requested challenges.
PS: You can follow this thread if you wish to have more information from:
freeCodeCamp support: FCC Support
github test repository issues: github issues
Any question or doubt, feel free to ask me in the comments section.
No comments