Back End Development and APIs Projects - Timestamp Microservice

**Hola. Estoy estancada con el ejercicio de time stamp. **
En replit pasa todas las pruebas con las diferentes rutas. Por favor una ayuda, llevo horas intentando.

este es mi codigo:

// index.js
// where your node app starts

// init project
var express = require(‘express’);
var app = express();
bodyParser = require(“body-parser”);

// enable CORS (Cross-origin resource sharing - Wikipedia)
// so that your API is remotely testable by FCC
var cors = require(‘cors’);
app.use(cors({optionsSuccessStatus: 200})); // some legacy browsers choke on 204

// Serving static files in Express
app.use(express.static(‘public’));

// My code

// Middleware para manejar JSON y formularios
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.get(“/:date?”, function (req, res) {
const date = req.params.date;
const newDateNow = new Date();

const options = { weekday: ‘short’, year: ‘numeric’, month: ‘short’, day: ‘numeric’, hour: ‘2-digit’, minute: ‘2-digit’, second: ‘2-digit’, timeZoneName: ‘short’ };
const formaterDate = newDateNow.toLocaleString(‘es-ES’, options);

if (!date) {
res.json({ unix: Date.now(), utc: formaterDate });
} else {
const timestamp = parseInt(date);

if (!isNaN(timestamp)) {
  const newDate = new Date(timestamp);
  const formattedDate = newDate.toLocaleString('es-ES', options);
  res.json({ unix: timestamp, utc: formattedDate });
} else {
  res.json({ error: 'Invalid date' });
}

}
})
// 1451001600000
// 2015-12-25

// your first API endpoint…
app.get(“/api/hello”, function (req, res) {
res.json({greeting: ‘hello API’});
});

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

Enlaces:

Verifica la hora en la computadora
Check the time on the computer
Intenta reordenar tus rutas para que las más específicas vengan después de las generales
try reordering your routes so that the more specific routes come after the general ones

// ... existing code ...

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

// Move the date route to the bottom
app.get("/api/:date?", function (req, res) {
  // ... date handling logic ...
});

// ... rest of the code ...

El tiempo en la computadora debe ser correcto

1 Like

The requirement is to have a /api/:date? endpoint. You do not have that.

You are not returning the correct object. It must match the specifications of the requirements. Look at the examples in the tests.

1 Like

Thanks, I hadn’t noticed that. jejeje…

1 Like

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