Session 15: CSP bugs fixed, QA passed, marketing materials ready
This commit is contained in:
parent
0cefaf71d1
commit
58bbc9965d
9 changed files with 456 additions and 19 deletions
66
projects/business/marketing/reddit-posts.md
Normal file
66
projects/business/marketing/reddit-posts.md
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# Reddit Posts
|
||||
|
||||
---
|
||||
|
||||
## r/webdev
|
||||
|
||||
**Title:** Built an HTML-to-PDF API — looking for feedback on the API design
|
||||
|
||||
**Body:**
|
||||
|
||||
Hey r/webdev,
|
||||
|
||||
I've been working on a small API service called [DocFast](https://docfast.dev) that converts HTML or Markdown to PDF. The idea came from rebuilding the same Puppeteer-based PDF pipeline across multiple projects.
|
||||
|
||||
The basic idea: POST your HTML, get a PDF back. It also has built-in templates for common docs like invoices so you can just pass JSON data instead of writing HTML.
|
||||
|
||||
Quick example:
|
||||
|
||||
```javascript
|
||||
const res = await fetch('https://docfast.dev/v1/convert/html', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': 'Bearer YOUR_KEY',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
html: '<h1>Hello</h1><p>This becomes a PDF.</p>',
|
||||
options: { format: 'A4' }
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
There's a free tier (100 PDFs/month, no credit card) if anyone wants to try it.
|
||||
|
||||
I'm specifically looking for feedback on:
|
||||
- The API design — does the interface feel intuitive?
|
||||
- What templates would be most useful? (Currently have invoice, receipt, report)
|
||||
- Anything you'd expect from a PDF API that's missing?
|
||||
|
||||
Docs are at https://docfast.dev/docs. Happy to answer any questions about the architecture too (Express + Puppeteer with a browser pool).
|
||||
|
||||
---
|
||||
|
||||
## r/node
|
||||
|
||||
**Title:** Managing a Puppeteer browser pool for PDF generation — lessons learned
|
||||
|
||||
**Body:**
|
||||
|
||||
I built an API service ([DocFast](https://docfast.dev)) that generates PDFs from HTML using Puppeteer, and wanted to share some things I learned about running Puppeteer in production with Node.
|
||||
|
||||
**The problem:** Launching a new Chromium instance per request is slow (~2-3s). For an API that needs to respond quickly, that's not acceptable.
|
||||
|
||||
**The solution:** A browser pool. I keep a set of warm Chromium instances and create new *pages* (not browsers) per request. New page creation takes ~50ms vs seconds for a cold browser launch.
|
||||
|
||||
Key things I learned:
|
||||
|
||||
1. **Memory management matters.** Each Chromium instance uses 100-300MB. You need to cap your pool size based on available memory and restart instances periodically to avoid leaks.
|
||||
|
||||
2. **Page cleanup is critical.** After each PDF generation, you need to properly close the page and clean up listeners. Forgetting this leads to slow memory leaks that only show up after hours of traffic.
|
||||
|
||||
3. **Graceful degradation.** If all pooled instances are busy, you have two choices: queue the request or spin up a temporary instance. I went with queuing + a small overflow pool.
|
||||
|
||||
4. **Font rendering is OS-dependent.** The same HTML can look different depending on what fonts are installed on the host system. I ended up bundling a standard set of fonts in the Docker image.
|
||||
|
||||
The API is live at https://docfast.dev if anyone wants to poke at it (free tier, 100 PDFs/mo). But mostly curious if others have dealt with similar Puppeteer pooling challenges and what approaches worked for you.
|
||||
Loading…
Add table
Add a link
Reference in a new issue