Good solution but not passing tests

Tell us what’s happening:
I believe the output to match the output desired. However, the tests are not passing. The solution is hosted at the following URL:
http://ec2-35-166-130-144.us-west-2.compute.amazonaws.com/

Your code so far

var express = require('express');
var app = express();
var cors = require('cors');
app.use(cors({optionsSuccessStatus: 200}));  // some legacy browsers choke on 204
app.use(express.static('public'));
app.get("/", function (req, res) {
  res.sendFile(__dirname + '/views/index.html');
});

app.get("/api/hello", function (req, res) {
  res.json({greeting: 'hello API'});
});

app.route('/api/timestamp/:date?')
  .get((req, res) => {
    let date = undefined;
    if (!req.params.date)
    {
      date = new Date(Date.now())
    }
    else
    {
      date = new Date(req.params.date);
      if (isNaN(date))
      {
        date = new Date(Number(req.params.date));
      }
    }
    if (isNaN(date))
    {
      res.status(400).json({
          error: "Invalid Date"
      });
    }
    else{
      res.json({
        unix: date.getTime(),
        utc: date.toUTCString(),
      });
    }
  });

// listen for requests :)
var listener = app.listen(80, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36.

Challenge: Timestamp Microservice

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Welcome, optimistrjj.

I see these errors in the browser console:

Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint '<URL>'. 
This request has been blocked; the content must be served over HTTPS.

Mixed Content: The page at 'https://www.freecodecamp.org/learn/apis-and-microservices/apis-and-microservices-projects/timestamp-microservice' 
was loaded over HTTPS, but requested an insecure XMLHttpRequest
 endpoint 'http://ec2-35-166-130-144.us-west-2.compute.amazonaws.com/api/timestamp/2016-12-25'. 
This request has been blocked; the content must be served over HTTPS.

I think those errors are self-explanatory.

Hope this helps

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.