diff --git a/README.md b/README.md
index a2de7654..b40f4a39 100644
--- a/README.md
+++ b/README.md
@@ -32,8 +32,9 @@ The webserver started by express.js has one JSON endpoint to generate PDFs.
Will generate a PDF based on the given `payload` data and returns the pdf file as a stream
```json5
{
- "content": "", // required - HTML string/handlebars template to be converted to PDF,
- "context": {}, // object with the data to be passed to handlebars template engine
+ "goto": "", // optional - URL to the HTML content/handlebars template to be converted to PDF. This option overrides the content when present.
+ "content": "", // required when goto is not present - HTML string/handlebars template to be converted to PDF,
+ "context": {}, // object with the data to be passed to handlebars template engine
"orientation": "portrait", // optional - possible values ["portrait", "landscape"]
"format": "A4", // optional - possible values ["Letter", "Legal", "Tabloid", "Ledger", "A0", "A1", "A2", "A3", "A4", "A5", "A6"]
"header": "", // optional - HTML template for the print header. See https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions
diff --git a/src/__test__/payloadValidator.spec.ts b/src/__test__/payloadValidator.spec.ts
new file mode 100644
index 00000000..91496799
--- /dev/null
+++ b/src/__test__/payloadValidator.spec.ts
@@ -0,0 +1,10 @@
+import { validatePayload } from '../payloadValidator'
+
+describe('src/payloadValidator.ts', () => {
+ it('should only allow payload with one of content or goto options exclusively', () => {
+ let errors = validatePayload({})
+ expect(errors.content[0]).toMatch(/html filed is required /)
+ errors = validatePayload({ content: '>', goto: 'https://example.com' })
+ expect(Object.keys(errors).length).toBe(0)
+ })
+})
diff --git a/src/payloadValidator.ts b/src/payloadValidator.ts
index eb6e2d7e..dd5a4e2a 100644
--- a/src/payloadValidator.ts
+++ b/src/payloadValidator.ts
@@ -1,7 +1,7 @@
export function validatePayload(body: Record = {}): Record {
const errors: Record = {}
- if (!body.content) {
- errors.content = ['html filed is required.']
+ if (!body.content && !body.goto) {
+ errors.content = ['html filed is required when goto is not present.']
}
if (body.content && body.content.includes('