mirror of
https://github.com/tomru/pdfer.git
synced 2026-03-03 06:27:19 +01:00
make pdfs
This commit is contained in:
22
index.js
22
index.js
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user