Skip to content

Commit

Permalink
Next release (#99)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: changes to parser

* feat: Add support for Accept-Language header
* fix: support for CDATA in oembed (#98)

Co-authored-by @adrian-seijo
Co-authored-by: Stef Kors <stef@beamapp.co>
  • Loading branch information
jacktuck committed Oct 23, 2022
1 parent 694b4ae commit c4d9a31
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 177 deletions.
1 change: 1 addition & 0 deletions Procfile
@@ -0,0 +1 @@
web: node example.js
10 changes: 9 additions & 1 deletion README.md
Expand Up @@ -27,7 +27,15 @@ npm install unfurl.js
- `follow?: number` - maximum redirect count. 0 to not follow redirect
- `compress?: boolean` - support gzip/deflate content encoding
- `size?: number` - maximum response body size in bytes. 0 to disable
- `userAgent?: string` - User-Agent string is often used for content negotiation
- `headers?: Headers | Record<string, string> | Iterable<readonly [string, string]> | Iterable<Iterable<string>>` - map of request headers, overrides the defaults

Default headers:
```
{
'Accept': 'text/html, application/xhtml+xml',
'User-Agent': 'facebookexternalhit'
}
```
---
#
```typescript
Expand Down
44 changes: 44 additions & 0 deletions example.js
@@ -0,0 +1,44 @@
const http = require("http");
const { parse } = require("url");
const { unfurl } = require("./dist");

http
.createServer(function (req, res) {
const isUrl = /https?:\/\//;
const { url } = parse(req.url, true).query;

if (!url) {
res.writeHead(400, "Please submit a url with querystring");
res.end();
return;
}

if (!isUrl.test(url)) {
res.writeHead(400, "Please only submit http(s) urls");
res.end();
return;
}

res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader(
"Access-Control-Allow-Methods",
"GET, PUT, POST, DELETE, OPTIONS"
);
res.setHeader(
"Access-Control-Allow-Headers",
"Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
);

unfurl(url)
.then((data) => {
res.setHeader("Content-Type", "application/json");
res.writeHead(200);
res.end(JSON.stringify(data));
})
.catch((err) => {
console.error(err);
res.writeHead(500, err);
res.end();
});
})
.listen(process.env.PORT || 3000); //eslint-disable-line

0 comments on commit c4d9a31

Please sign in to comment.