├── Procfile ├── docs ├── logo.png ├── heroku.png ├── logo.sketch ├── local-examples.md └── heroku.xml ├── .travis.yml ├── CHANGELOG.md ├── test ├── resources │ ├── special-chars.html │ ├── large-linked.html │ └── postmark-receipt.html ├── util │ └── index.js └── test-all.js ├── .env.sample ├── src ├── util │ ├── require-envs.js │ ├── logger.js │ ├── express.js │ └── validation.js ├── middleware │ ├── require-https.js │ ├── error-responder.js │ └── error-logger.js ├── config.js ├── index.js ├── router.js ├── app.js ├── http │ └── render-http.js └── core │ └── render-core.js ├── .vscode └── launch.json ├── .eslintrc ├── .gitignore ├── LICENSE ├── app.json ├── package.json └── README.md /Procfile: -------------------------------------------------------------------------------- 1 | web: NODE_ENV=production node src/index.js -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adaptive/url-to-pdf-api/master/docs/logo.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | env: 5 | - ALLOW_HTTP=true 6 | -------------------------------------------------------------------------------- /docs/heroku.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adaptive/url-to-pdf-api/master/docs/heroku.png -------------------------------------------------------------------------------- /docs/logo.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adaptive/url-to-pdf-api/master/docs/logo.sketch -------------------------------------------------------------------------------- /docs/local-examples.md: -------------------------------------------------------------------------------- 1 | # Local examples 2 | 3 | curl -o html.pdf -XPOST -d@test/resources/large-linked.html -H"content-type: text/html" https://url-to-pdf-api.herokuapp.com/api/render -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | * change the `:html` output to return `document.documentElement.innerHTML` instead of previously used `document.body.innerHTML` 4 | 5 | ## 1.0.0 6 | 7 | * initial version 8 | -------------------------------------------------------------------------------- /test/resources/special-chars.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 |7 | special characters: ä ö ü 8 |
9 | 10 | 11 | -------------------------------------------------------------------------------- /.env.sample: -------------------------------------------------------------------------------- 1 | # Guide: 2 | # 3 | # 1. Copy this file to .env 4 | # 5 | # cp .env.sample .env 6 | # 7 | # 2. Fill the blanks 8 | 9 | NODE_ENV=development 10 | PORT=9000 11 | ALLOW_HTTP=true 12 | 13 | # Warning: PDF rendering does not work in Chrome when it is in headed mode. 14 | DEBUG_MODE=false 15 | -------------------------------------------------------------------------------- /test/util/index.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | 4 | function getResource(name) { 5 | const filePath = path.join(__dirname, '../resources', name); 6 | return fs.readFileSync(filePath, { encoding: 'utf-8' }); 7 | } 8 | 9 | module.exports = { 10 | getResource, 11 | }; 12 | -------------------------------------------------------------------------------- /src/util/require-envs.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-process-env */ 2 | 3 | const _ = require('lodash'); 4 | 5 | function requireEnvs(arr) { 6 | _.each(arr, (varName) => { 7 | if (!process.env[varName]) { 8 | throw new Error(`Environment variable not set: ${varName}`); 9 | } 10 | }); 11 | } 12 | 13 | module.exports = requireEnvs; 14 | -------------------------------------------------------------------------------- /src/middleware/require-https.js: -------------------------------------------------------------------------------- 1 | const createRequireHttps = () => function RequireHttps(req, res, next) { 2 | if (req.secure) { 3 | // Allow requests only over https 4 | return next(); 5 | } 6 | 7 | const err = new Error('Only HTTPS allowed.'); 8 | err.status = 403; 9 | next(err); 10 | }; 11 | 12 | module.exports = createRequireHttps; 13 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "program": "${workspaceFolder}/src/index.js", 12 | "env": { 13 | "NODE_ENV": "development", 14 | "PORT": "9000", 15 | "ALLOW_HTTP": "true", 16 | } 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "amd": true, 5 | "node": true, 6 | "es6": true 7 | }, 8 | "extends": "airbnb-base", 9 | "rules": { 10 | "no-implicit-coercion": "error", 11 | "no-process-env": "error", 12 | "no-path-concat": "error", 13 | "import/no-extraneous-dependencies": ["error", {"devDependencies": true}], 14 | "no-use-before-define": ["error", { "functions": false }], 15 | "no-underscore-dangle": "off", 16 | "no-console": "off", 17 | "comma-dangle": ["error", { 18 | "arrays": "always-multiline", 19 | "objects": "always-multiline", 20 | "imports": "always-multiline", 21 | "exports": "always-multiline", 22 | "functions": "ignore" 23 | }], 24 | "function-paren-newline": "off" 25 | } 26 | } -------------------------------------------------------------------------------- /src/util/logger.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const winston = require('winston'); 3 | const _ = require('lodash'); 4 | const config = require('../config'); 5 | 6 | const COLORIZE = config.NODE_ENV === 'development'; 7 | 8 | function createLogger(filePath) { 9 | const fileName = path.basename(filePath); 10 | 11 | const logger = new winston.Logger({ 12 | transports: [new winston.transports.Console({ 13 | colorize: COLORIZE, 14 | label: fileName, 15 | timestamp: true, 16 | })], 17 | }); 18 | 19 | _setLevelForTransports(logger, config.LOG_LEVEL || 'info'); 20 | return logger; 21 | } 22 | 23 | function _setLevelForTransports(logger, level) { 24 | _.each(logger.transports, (transport) => { 25 | // eslint-disable-next-line 26 | transport.level = level; 27 | }); 28 | } 29 | 30 | module.exports = createLogger; 31 | -------------------------------------------------------------------------------- /test/resources/large-linked.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
32 |
|
165 | ||||||||||||||||||||||