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: