Files
dougal-software/lib/www/server/api/middleware/event/get/index.js
D. Berge d9f4583224 Implement GET middleware for events.
Produces a choice of outputs: JSON, GeoJSON, Seis+JSON and HTML.
2021-05-15 01:57:45 +02:00

28 lines
642 B
JavaScript

const json = require('./json');
const geojson = require('./geojson');
const seis = require('./seis');
const html = require('./html');
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,
};
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);
}
}