https://github.com/tldraw/cloudflare-workers-unfurl
Unfurl URLs on Cloudflare Workers using the built-in HTMLRewriter API.
https://github.com/tldraw/cloudflare-workers-unfurl
Last synced: about 2 months ago
JSON representation
Unfurl URLs on Cloudflare Workers using the built-in HTMLRewriter API.
- Host: GitHub
- URL: https://github.com/tldraw/cloudflare-workers-unfurl
- Owner: tldraw
- License: mit
- Created: 2024-07-22T15:13:39.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-23T08:34:22.000Z (11 months ago)
- Last Synced: 2025-05-07T14:22:20.161Z (about 2 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cloudflare-workers-unfurl
A tiny utility to get basic information about a URL on Cloudflare Workers using the built-in HTMLRewriter API.
## Usage
```
npm install cloudflare-workers-unfurl
```There are two exports: `unfurl` and `handleUnfurlRequest`.
`unfurl` is the main function that does the work. It takes a URL and returns a promise that resolves to an object with the following properties:
- `title`: The title of the page
- `description`: The description of the page
- `image`: The URL of the social image
- `favicon`: The URL of the favicon```js
import { unfurl } from "cloudflare-workers-unfurl";const result = await unfurl("https://example.com");
result.title; // 'Example Domain'
````handleUnfurlRequest` is a function that takes a `Request` object and returns a promise that resolves to a `Response` object. It uses `unfurl` to get the information about the URL in the `url` query parameter of the request and returns it as JSON.
```js
import { AutoRouter } from "itty-router";
import { handleUnfurlRequest } from "cloudflare-workers-unfurl";const router = AutoRouter();
router.get("/unfurl", handleUnfurlRequest);
export default router;
```## License
MIT