Tell us what’s happening:
So I uploaded my code on Heroku app and it is live on here: https://timestamp-exercise.herokuapp.com/
And my github source code here: https://github.com/synerjay/timestamp-exercise
But i still cannot pass this page?? It only passed the first story, even though everything seem to work on the microservice.
I did this exercise without cloning the Github repo from FCC. Is this the reason why it’s not passing?
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Timestamp Microservice
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
jenovs
January 28, 2021, 6:16am
2
If you open network tab you’ll see that the requests are blocked because of CORS.
https://expressjs.com/en/resources/middleware/cors.html
Relevant code in FCC boilerplate repo:
Sorry but I dont know what does that mean? I open the network tab and evrything seem to be fine.
Is that related to express? I 'm not using any express in my code btw.
jenovs
January 28, 2021, 6:45am
4
1 Like
Ok. I used the same code and retroifitted the provided Repl.it package and I got the first few stories passed except the last two:
const getTimestamp = date => ({ unix: date.getTime(), utc: date.toUTCString() });
app.get("/api/timestamp/:date", function (req, res) {
const dateString = req.params.date;
console.log(dateString);
let timestamp;
if (dateString === undefined || dateString.trim() === "") {
let currentTime = new Date();
timestamp = getTimestamp(currentTime);
} else {
const date = !isNaN(dateString) ? new Date(parseInt(dateString)) : new Date(dateString);
if (!isNaN(date.getTime())) {
timestamp = getTimestamp(date);
} else {
timestamp = { error : "Invalid Date" };
}
}
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(timestamp));
})
I made the condition for an “undefined” dateString and empty string and yet I cant pass the last two stories . Any insights? Thanks
This is the live link: https://boilerplate-project-timestamp-3.synerjay.repl.co/
Thank you! It worked! Is that a special feature in request parameters? I only learned /:parameters without the question mark. Would love to learn more about it
jenovs
January 28, 2021, 8:14am
8
Url supports regex (?
means 0 or 1 of preceding token, or in simpler words - make optional)
1 Like
system
Closed
July 29, 2021, 8:14pm
9
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.