Skip to content

Commit

Permalink
refactor: rewrite to honojs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonraimondi committed Mar 20, 2024
1 parent a38ad92 commit c4896ca
Show file tree
Hide file tree
Showing 43 changed files with 3,247 additions and 2,501 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NODE_ENV=development

ALLOW_LIST=jasonraimondi.com,github.com

STORAGE_PROVIDER=
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- next
tags:
- '*'

Expand Down Expand Up @@ -31,6 +32,8 @@ jobs:
run: |
if [[ $GITHUB_REF == refs/heads/main ]]; then
echo "version=latest" >> $GITHUB_OUTPUT
elif [[ $GITHUB_REF == refs/heads/next ]]; then
echo "version=nightly" >> $GITHUB_OUTPUT
else
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
Expand Down
14 changes: 7 additions & 7 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"printWidth": 120,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all"
}
arrowParens: avoid
bracketSpacing: true
printWidth: 100
trailingComma: all
tabWidth: 2
semi: true
singleQuote: false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ USER pwuser
WORKDIR /app
COPY package.json pnpm-lock.yaml /app
RUN pnpm install --production false
COPY tsconfig.json /app/
COPY tsconfig.json tsconfig.build.json /app/
COPY src /app/src
RUN pnpm build

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2021 Jason Raimondi <[email protected]>
Copyright 2024 Jason Raimondi <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A URL to PNG generator over HTTP with a fairly simple API accessed via query par
Run the following command:

```
docker run --rm -p 3000:3000 ghcr.io/jasonraimondi/url-to-png
docker run --rm -p 3089:3089 ghcr.io/jasonraimondi/url-to-png
```

On the hub: [Link to DockerHub](https://hub.docker.com/r/jasonraimondi/url-to-png/)
Expand All @@ -25,6 +25,8 @@ Serve the project
git clone [email protected]:jasonraimondi/url-to-png.git
cd url-to-png
pnpm install
# you may need to run this command if you are having issues with playwright
pnpm exec playwright install
pnpm dev
```

Expand All @@ -41,21 +43,21 @@ pnpm dev
- `isDarkMode: boolean` - Prefer color scheme dark - **Optional** - Default: `false`
- `deviceScaleFactor: number` - Specify device scale factor (can be thought of as dpr) - **Optional** - Default: `1`

Try it out at `localhost:3000?url=https://www.jasonraimondi.com&isDarkMode=true` and you should get back an image capture of my website homepage.
Try it out at `localhost:3089?url=https://www.jasonraimondi.com&isDarkMode=true` and you should get back an image capture of my website homepage.

All sorts of combos work:

```
http://localhost:3000?url=https://jasonraimondi.com
http://localhost:3000?url=https://jasonraimondi.com&forceReload=true
http://localhost:3000?url=https://jasonraimondi.com&isFullPage=true
http://localhost:3000?url=https://jasonraimondi.com&isMobile=true
http://localhost:3000?url=https://jasonraimondi.com&isDarkMode=true
http://localhost:3000?url=https://jasonraimondi.com&width=400&height=400
http://localhost:3000?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400
http://localhost:3000?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400
http://localhost:3000?url=https://jasonraimondi.com&isFullPage=true&isMobile=true&width=400&height=400&viewPortHeight=400&viewPortWidth=400
http://localhost:3000?url=https://jasonraimondi.com&isMobile=true&isFullPage=true&viewPortWidth=375&width=375&deviceScaleFactor=1
http://localhost:3089?url=https://jasonraimondi.com
http://localhost:3089?url=https://jasonraimondi.com&forceReload=true
http://localhost:3089?url=https://jasonraimondi.com&isFullPage=true
http://localhost:3089?url=https://jasonraimondi.com&isMobile=true
http://localhost:3089?url=https://jasonraimondi.com&isDarkMode=true
http://localhost:3089?url=https://jasonraimondi.com&width=400&height=400
http://localhost:3089?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400
http://localhost:3089?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400
http://localhost:3089?url=https://jasonraimondi.com&isFullPage=true&isMobile=true&width=400&height=400&viewPortHeight=400&viewPortWidth=400
http://localhost:3089?url=https://jasonraimondi.com&isMobile=true&isFullPage=true&viewPortWidth=375&width=375&deviceScaleFactor=1
```

## System Requirements
Expand Down Expand Up @@ -147,6 +149,24 @@ STORAGE_PROVIDER=filesystem
IMAGE_STORAGE_PATH=/tmp/foo
```

## Metrics

You can enable metrics by setting `METRICS=true` in your `.env` file. This will expose a `/metrics` endpoint for Prometheus to scrape.

```json
{
"poolMetrics": {
"spareResourceCapacity": 8,
"size": 2,
"available": 2,
"borrowed": 0,
"pending": 0,
"max": 10,
"min": 2
}
}
```

## Sources

- Upstream Repository: [https://git.jasonraimondi.com/jason/url-to-png](https://git.jasonraimondi.com/jason/url-to-png)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: jasonraimondi/url-to-png
build: .
ports:
- 3000:3000
- 3089:3089
environment:
NODE_ENV: debug
BROWSER_WAIT_UNTIL: networkidle
24 changes: 10 additions & 14 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<img src="http://localhost:3000/?url=https://jasonraimondi.com">
<img src="http://localhost:3000/?url=https://aircraftturbineworks.com">
<img src="http://localhost:3000/?url=https://reddit.com">
<img src="http://localhost:3000/?url=https://bbc.com">
<img src="http://localhost:3000/?url=https://aol.com">
<img src="http://localhost:3000/?url=https://ask.com">
<img src="http://localhost:3000/?url=https://github.com">
<img src="http://localhost:3000/?url=https://google.com">
<img src="http://localhost:3000/?url=https://imgur.com">
<img src="http://localhost:3000/?url=https://candy.com">
<img src="http://localhost:3000/?url=https://amazon.com">
<img src="http://localhost:3000/?url=https://etsy.com">
<img src="http://localhost:3000/?url=https://wayfair.com">
<img src="http://localhost:3000/?url=https://en.wikipedia.org/wiki/Candy">
<img src="http://localhost:3089/?url=https://jasonraimondi.com">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&forceReload=true">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&isFullPage=true">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&isMobile=true">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&isDarkMode=true">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&width=400&height=400">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&viewPortHeight=400&viewPortWidth=400">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&isFullPage=true&isMobile=true&width=400&height=400&viewPortHeight=400&viewPortWidth=400">
<img src="http://localhost:3089/?url=https://jasonraimondi.com&isMobile=true&isFullPage=true&viewPortWidth=375&width=375&deviceScaleFactor=1">
6 changes: 0 additions & 6 deletions nodemon.json

This file was deleted.

55 changes: 25 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,44 @@
"scripts": {
"clean": "rm -rf dist/*",
"serve": "node -r dotenv/config dist/main.js",
"dev": "nodemon",
"compile": "tsc",
"dev": "tsx --watch src/main.ts | pino-pretty",
"compile": "tsc --project tsconfig.build.json",
"build": "run-s clean compile",
"format": "prettier --write \"./src/**/*.ts\""
"format": "prettier --write \"./src/**/*.ts\"",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"engines": {
"node": ">= 20",
"pnpm": ">= 8.4.0"
},
"engineStrict": true,
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"dependencies": {
"@aws-sdk/client-s3": "^3.353.0",
"@fastify/helmet": "^10.1.1",
"@fastify/rate-limit": "^8.0.1",
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-fastify": "^10.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"dotenv": "^16.1.4",
"fastify": "^4.18.0",
"@aws-sdk/client-s3": "^3.536.0",
"@hono/node-server": "^1.8.2",
"@jmondi/string-encrypt-decrypt": "^0.0.6",
"dotenv": "^16.4.5",
"generic-pool": "^3.9.0",
"hono": "^4.1.2",
"md5": "^2.3.0",
"nano": "^10.1.2",
"playwright": "^1.35.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"sharp": "^0.32.6",
"winston": "^3.9.0",
"winston-transport": "^4.5.0"
"nano": "^10.1.3",
"pino": "^8.19.0",
"playwright": "^1.42.1",
"sharp": "^0.33.2",
"zod": "^3.22.4",
"zod-ff": "^1.4.0"
},
"devDependencies": {
"@types/node": "^20.3.1",
"@types/md5": "^2.3.5",
"@types/node": "^20.11.29",
"@vitest/coverage-v8": "^1.4.0",
"cross-env": "^7.0.3",
"nodemon": "^2.0.22",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
"pino-pretty": "^10.3.1",
"prettier": "^3.2.5",
"tsx": "^4.7.1",
"typescript": "^5.4.2",
"vitest": "^1.4.0"
}
}
Loading

0 comments on commit c4896ca

Please sign in to comment.