Commit fb90904b authored by Fred Chasen's avatar Fred Chasen

keep browser connection alive

parent 90d11eb5
......@@ -13,13 +13,16 @@ const requestLogger = require('koa-logger');
const validate = require('koa-validate');
const mount = require('koa-mount');
const pdf = require('./pdf');
const printer = require('./printer');
// const pdf = require('./pdf');
// const Printer = require('pagedjs-cli');
const printerRoute = require('./printer');
const app = new Koa();
const router = new Router();
router.post('/', printer);
router.post('/', printerRoute);
app.use(cors());
......@@ -36,16 +39,22 @@ app.use(bodyParser(
validate(app);
// app.use(ctx => {
// console.log(ctx.request.body);
// app.use((ctx, next) => {
// ctx.printer = printer;
// next();
// });
app.use(router.routes())
app.listen(PORT, () => {
let server = app.listen(PORT, () => {
console.warn(`Printer server listening on ${PORT}, in ${process.env.NODE_ENV} mode`);
});
process.on('SIGTERM', () => {
console.log('Closing http server.');
printer.close();
server.close();
});
module.exports = app;
const fs = require('fs');
const Printer = require('pagedjs-cli');
const printer = new Printer();
printer.setup();
printer.on("page", (page) => {
console.debug("Rendering: Page " + (page.position + 1))
});
printer.on("rendered", (msg) => {
console.debug("Generating");
});
printer.on("postprocessing", (msg) => {
console.debug("Processing");
});
module.exports = async (ctx) => {
ctx.type = 'application/pdf';
ctx.attachment('out.pdf');
const { url, html, options, headers } = ctx.request.body;
// console.debug('URL: ', url);
// console.debug('HTML: ', html);
console.debug('URL: ', url);
console.debug('HTML: ', html && html.length);
// console.debug('OPTIONS: ', options);
// console.debug('HEADERS: ', headers);
let printer = new Printer();
printer.on("page", (page) => {
console.debug("Rendering: Page " + (page.position + 1))
});
printer.on("rendered", (msg) => {
console.debug("Generating");
});
printer.on("postprocessing", (msg) => {
console.debug("Processing");
});
let file;
if (url) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment