Files
pdfer/index.js
Thomas Ruoff d806327bf9 make pdfs
2017-02-16 00:47:52 +01:00

37 lines
1.0 KiB
JavaScript

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/pdf/:template', (req, res) => {
const templateName = req.params.template;
const options = req.body;
templates.get(templateName, options, (err, texDocument) => {
if (err) {
console.error('Error:', err.code, 'for', req.url);
res.sendStatus(500).end('Something went wrong while generating Tex source');
return;
}
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();
});
});
});
app.use(express.static('dist'));
app.listen(5000);