Skip to content

Commit

Permalink
fix: support for CDATA in oembed (#98)
Browse files Browse the repository at this point in the history
Co-authored-by @adrian-seijo
  • Loading branch information
jacktuck committed Oct 23, 2022
1 parent 51597f6 commit 127d61f
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 163 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node example.js
44 changes: 44 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 127d61f

Please sign in to comment.