-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support for CDATA in oembed (#98)
Co-authored-by @adrian-seijo
- Loading branch information
Showing
8 changed files
with
440 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: node example.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.