Timestamp microservice project issues

I have completed my entry for the Timestamp microservice project. It works properly on my local machine, and I have also uploaded it to my personal web server and it works fine from there, too. For diagnostic purposes, I added some console.log statements to my Node file just to make sure the endpoint was processing properly.

When I try to submit my project, I see the test output all fails - but according to my logging, not even all of the tests ran. When I manually verify the output of my code against the inputs that I see from my logging, everything seems to be correct. The Content-Type header is application/json, the JSON response has the proper properties and values. I’m at a loss as to what could be causing the hangup.

When I log output from each request, the format is in 3 lines. The third line is the exact object that gets sent to the Express res.json() method. My log output looks like this:

Timestamp microservice started on port 6001

-----Starting Request-----
Request URL: /2016-12-25
{ unix: 1482624000000, utc: 'Sun, 25 Dec 2016 00:00:00 GMT' }

-----Starting Request-----
Request URL: /2016-12-25
{ unix: 1482624000000, utc: 'Sun, 25 Dec 2016 00:00:00 GMT' }

-----Starting Request-----
Request URL: /1482624000000
{ unix: 1482624000000, utc: 'Sun, 25 Dec 2016 00:00:00 GMT' }

-----Starting Request-----
Request URL: /this-is-not-a-date
{ error: 'Invalid Date' }

The project is hosted at https://www.christianspeegle.com in case anyone wants to test the output themselves.

Do you have your code available on github? Have you tried using replit instead of your server? (No idea why it’d make a difference just something to try.)

1 Like

The source can be found at github.com/christianspeegle/fcc-backend

I will try using replit and see if that helps any.

I got the code uploaded to replit along with the changes needed to make it work there (on my server, I used Nginx to reverse-proxy /api/timestamp requests to the microservice, which is why the Express endpoint doesn’t reference the URI). Still no luck, unfortunately. The replit is at https://repl.it/@christianspeegl/fcc-backend-timestamp

I’ll give it a look in a few, I transferred my project from glitch (the old online IDE FCC was using) and things seem good. Gotta take care of some chores atm.

The json looks good. The boilerplate for this challenge and my working one both have CORS enabled for testing:

// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
// so that your API is remotely testable by FCC
var cors = require('cors');
app.use(cors({optionSuccessStatus: 200})); // some legacy browsers choke on 204

This is at the top of server.js after declaring app.

Hmmm…I added that to my own code and most of the tests are passing now. I will just have to figure out why it isn’t accepting my empty time now, as the endpoint works for me. I didn’t realize FCC checked for CORS content, thanks for that tidbit.

I figured it out. It bothered me that the app wasn’t receiving a request from the tests for the blank date, so I went digging in my Nginx logs. Turns out, upon receiving the request at /api/timestamp, Nginx was sending a 301 with Location: /api/timestamp/ to get the trailing slash. The test suite apparently doesn’t follow the redirect, which is why the FCC test failed but my own testing worked fine (Postman also ignores CORS in general).

In the process, I also learned why I needed CORS enabled (I naively assumed that FCC tests ran on the backend, but my Nginx logs showed testing coming from my own IP and browser).

Thank you all for your help. Now that I have thoroughly embarrassed myself, I can go to bed.

Don’t wanna keep you up but, does it pass the FCC tests now?

Yes it does. I’m not sure why FCC tests are not configured to follow 301s but I just switched to regex matching on my proxy block, so it will work fine moving forward. Again, thank you for taking the time.

1 Like