Skip to content

Commit

Permalink
Merge pull request #52 from doublecrowngaming/add-header-options
Browse files Browse the repository at this point in the history
Add support for any request header
  • Loading branch information
Oscar Franco authored Jan 3, 2020
2 parents ae8dd14 + fd186da commit 0a3e347
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Additionally you can pass an options object which should add more functionality
| ------------- |:-------------:|
| imagesPropertyType (**optional**) (ex: 'og') | Fetches images only with the specified property, `meta[property='${imagesPropertyType}:image']` |
| language (**optional**) (ex: 'de', 'en-US') | Fetch content with specific language |
| headers (**optional**) (ex: { 'user-agent': 'googlebot' }) | Add request headers to fetch call |


```javascript
Expand All @@ -48,6 +49,10 @@ LinkPreview.getPreview(
{
imagesPropertyType: 'og', // fetches only open-graph images
language: 'fr-CA', // fetches site for French language
headers: {
'user-agent': 'googlebot', // fetches with googlebot crawler user agent
// ...other optional request headers
},
})
.then(data => console.debug(data));
```
Expand Down Expand Up @@ -122,4 +127,3 @@ yarn test
## License

MIT license

5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ exports.getPreview = function (text, options) {

if (detectedUrl) {
var fetchOptions = {}
if (options && options.language) {
if (options) {
fetchOptions.headers = {
'Accept-Language': options.language
'Accept-Language': options.language,
...options.headers,
}
}
fetch(detectedUrl, fetchOptions)
Expand Down

0 comments on commit 0a3e347

Please sign in to comment.