Skip to content

Commit

Permalink
Merge pull request #3 from dills122/updated-routes
Browse files Browse the repository at this point in the history
fixed routes and added basic error handling
  • Loading branch information
dills122 authored Oct 5, 2019
2 parents d0c7599 + 96c4a32 commit 231538e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
30 changes: 21 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
var express = require("express");
var app = express();
const express = require('express');
const app = express();
const port = parseInt(process.env.PORT, 10) || 8080;
const bodyParser = require('body-parser')
const weasyPrint = require("weasyprint-wrapper");

app.listen(8080, () => {
console.log("Server running on port 3000");
});
app.use(bodyParser.json({
limit: '2mb'
}));

app.listen(port);

app.get('/convert/stream', (req, res, next) => {
let inputStr = req.body.inputStr;
// let inputStr = "http://www.google.com";
let inputStr = req.body.inputStr || false;
if (!inputStr) {
return res.sendStatus(400).json({
error: "Missing inputStr"
});
}
let stream = weasyPrint(inputStr, {
pageSize: 'letter'
});
Expand All @@ -18,8 +26,12 @@ app.get('/convert/stream', (req, res, next) => {
});

app.get('/convert/base64', (req, res, next) => {
let inputStr = req.body.inputStr;
// let inputStr = "http://www.google.com";
let inputStr = req.body.inputStr || false;
if (!inputStr) {
return res.sendStatus(400).json({
error: "Missing inputStr"
});
}
let stream = weasyPrint(inputStr, {
pageSize: 'letter'
});
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weasyprint-docker",
"version": "0.1.1",
"version": "0.1.2",
"description": "a standalone weasyprint container with a simple api to communicate",
"main": "index.js",
"scripts": {
Expand All @@ -9,6 +9,7 @@
"author": "Dylan Steele",
"license": "MIT",
"dependencies": {
"body-parser": "^1.19.0",
"express": "4.17.1",
"weasyprint-wrapper": "0.1.2"
}
Expand Down

0 comments on commit 231538e

Please sign in to comment.