UNPKG

@fontoxml/fontoxml-development-tools

Version:

Development tools for Fonto.

40 lines (36 loc) 1.26 kB
import correlationIdRepository from './correlationIdRepository.js'; /** @typedef {import('../../src/getAppConfig.js').DevCmsConfig} DevCmsConfig */ /** * @param {DevCmsConfig} _config */ export default function configureDocumentRevisionGetRouteHandler(_config) { return (req, res) => { const { documentId, revisionId, context } = req.query; // Because these requests do not originate from the editor, but from an other server, we // have no edit session token. We do, however, have an correlationId which we may resolve // to the editSessionToken used by the corresponding call to the proxy. // For review this endpoint might also be called from the editor, in which case the // editSessionToken is provided as a query parameter. const editSessionToken = context ? JSON.parse(context).editSessionToken : correlationIdRepository.getEditSessionTokenForRequest(req); req.cms.loadRevision( documentId, revisionId, editSessionToken, (error, content) => { if (error) { if (error.status === 404) { res.status(404).end(); } else { res.status(500).end(); } return; } res.status(200) .set('content-type', 'application/json; charset=utf-8') .json({ content }); } ); }; }