Open
Description
The json middleware does not parse results as json if the content type is anything but application/json
, I would expect it to also work on content types like application/ld+json
. For instance:
import express from 'express';
const app = express();
app.use(express.json());
app.post('/', async (req, res) => {
console.log("Data posted", await req.body);
});
app.listen(3000, () => {
console.log('Listening on port 3000');
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: 'Hello world',
}),
});
});
returns
Listening on port 3000
Data posted { message: 'Hello world' }
On the other hand
import express from 'express';
const app = express();
app.use(express.json());
app.post('/', async (req, res) => {
console.log("Data posted", await req.body);
});
app.listen(3000, () => {
console.log('Listening on port 3000');
fetch('http://localhost:3000', {
method: 'POST',
headers: {
'Content-Type': 'application/ld+json',
},
body: JSON.stringify({
message: 'Hello world',
}),
});
});
returns
Listening on port 3000
Data posted {}