I have express.js API function which produce response like this:
// Copied from linux console/terminal
[
RowDataPacket {
KORISNIK: 'ddd',
MESEC: 5,
DATUM_PLACANJA: 2022-07-27T22:00:00.000Z
},
RowDataPacket {
KORISNIK: 'finalKorisnik',
MESEC: 5,
DATUM_PLACANJA: 2022-07-27T22:00:00.000Z
}
]
When I try accessing that endpoint through Postman, I get this result (which is okay)
// Copied from linux console/terminal
[
{
"KORISNIK": "ddd",
"MESEC": 5,
"DATUM_PLACANJA": "2022-07-27T22:00:00.000Z"
},
{
"KORISNIK": "finalKorisnik",
"MESEC": 5,
"DATUM_PLACANJA": "2022-07-27T22:00:00.000Z"
}
]
but when I try getting it from my reactjs application i get this response:
// Copied from google chrome console
Array [ {…}, {…} ]
0: Object { KORISNIK: true, MESEC: 5, DATUM_PLACANJA: "2022-07-27T22:00:00.000Z" }
DATUM_PLACANJA: "2022-07-27T22:00:00.000Z"
KORISNIK: true
MESEC: 5
<prototype>: Object { … }
1: Object { KORISNIK: false, MESEC: 5, DATUM_PLACANJA: "2022-07-27T22:00:00.000Z" }
DATUM_PLACANJA: "2022-07-27T22:00:00.000Z"
KORISNIK: false
MESEC: 5
<prototype>: Object { … }
length: 2
<prototype>: Array []
KalendarClanarina.js:32
As you can see, field KORISNIK has true and false values for some reason.
My React Application is parsing all API data good (30+ endpoints) up until now. Only difference I have is I have never requested data with date property so I guess problem is there.
I am simply fetching it from endpoint using fetch function like this:
fetch("http://localhost:3000" + endpoint, {
method: "GET"
})
.then((response) => {
response.json().then((data) => {
console.log(data)
})
})
EDIT: (here is server side code that)
router.get('/list', function(req, res) {
sql.query(`SELECT KORISNIK, MESEC, DATUM_PLACANJA FROM CLANARINA`, (err, resp) => {
if(err) {
console.log(err)
return res.status(500).end()
}
console.log(resp)
return res.json(resp)
})
})
KORISNIK is Varchar(32)
MESEC is Int
DATUM_PLACANJA is DATE
DATE. Notvarchar, notintetc, butDATE. I thought that might be helpful since I guess problem is in that - Aleksa Risticresponse.text()) just to be sure that the json is as expected? - Mischa