mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:37:07 +00:00
32 lines
744 B
JavaScript
32 lines
744 B
JavaScript
const json = require('./json');
|
|
const geojson = require('./geojson');
|
|
const seis = require('./seis');
|
|
const html = require('./html');
|
|
const csv = require('./csv');
|
|
const pdf = require('./pdf');
|
|
|
|
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,
|
|
"text/csv": csv,
|
|
"application/pdf": pdf
|
|
};
|
|
|
|
const mimetype = (handlers[req.query.mime] && req.query.mime) || req.accepts(Object.keys(handlers));
|
|
|
|
if (mimetype) {
|
|
res.set("Content-Type", mimetype);
|
|
await handlers[mimetype](req, res, next);
|
|
} else {
|
|
res.status(406).send();
|
|
next();
|
|
}
|
|
} catch (err) {
|
|
next(err);
|
|
}
|
|
}
|