make pdfs

This commit is contained in:
Thomas Ruoff
2017-02-16 00:47:52 +01:00
parent 7668fc3837
commit d806327bf9
5 changed files with 131 additions and 68 deletions

View File

@@ -2,26 +2,32 @@ const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const templates = require('./templates');
const renderer = require('./renderer');
app.use(bodyParser.json());
app.post('/generate/:template', (req, res) => {
app.post('/generate/pdf/:template', (req, res) => {
const templateName = req.params.template;
const options = req.body;
templates.get(templateName, options, (err, template) => {
templates.get(templateName, options, (err, texDocument) => {
if (err) {
console.error('Error:', err.code, 'for', req.url);
res.sendStatus(500).end('Something went wrong, call Thomas');
res.sendStatus(500).end('Something went wrong while generating Tex source');
return;
}
let result = template;
res.send(result);
res.end();
renderer(texDocument, (err, pdf) => {
if (err) {
console.error('Error:', err.code, 'for', req.url);
res.sendStatus(500).end('Something went wrong while baking the PDF');
return;
}
res.set('Content-Type', 'application/pdf');
res.send(pdf);
res.end();
});
});
});