2021-05-11 23:12:42 +02:00
|
|
|
const json = require('./json');
|
|
|
|
|
const geojson = require('./geojson');
|
|
|
|
|
const seis = require('./seis');
|
|
|
|
|
const html = require('./html');
|
2023-09-13 21:58:06 +02:00
|
|
|
const csv = require('./csv');
|
2021-05-13 20:17:39 +02:00
|
|
|
const pdf = require('./pdf');
|
2021-05-11 23:12:42 +02:00
|
|
|
|
|
|
|
|
module.exports = async function (req, res, next) {
|
|
|
|
|
try {
|
|
|
|
|
const handlers = {
|
|
|
|
|
"application/json": json,
|
|
|
|
|
"application/geo+json": geojson,
|
|
|
|
|
"application/vnd.seis+json": seis,
|
|
|
|
|
"text/html": html,
|
2023-09-13 21:58:06 +02:00
|
|
|
"text/csv": csv,
|
2021-05-13 20:17:39 +02:00
|
|
|
"application/pdf": pdf
|
2021-05-11 23:12:42 +02:00
|
|
|
};
|
2022-04-29 14:48:21 +02:00
|
|
|
|
2021-05-11 23:12:42 +02:00
|
|
|
const mimetype = (handlers[req.query.mime] && req.query.mime) || req.accepts(Object.keys(handlers));
|
2022-04-29 14:48:21 +02:00
|
|
|
|
2021-05-11 23:12:42 +02:00
|
|
|
if (mimetype) {
|
|
|
|
|
res.set("Content-Type", mimetype);
|
|
|
|
|
await handlers[mimetype](req, res, next);
|
|
|
|
|
} else {
|
|
|
|
|
res.status(406).send();
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
next(err);
|
|
|
|
|
}
|
|
|
|
|
}
|