Skip to content

Commit

Permalink
Ensure always return domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 14, 2018
1 parent 11c60f0 commit 07e4184
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const autoDomains = require('./auto-domains')

const REQ_TIMEOUT = 5000

const getDomain = url => (parseDomain(url) || {}).domain

const fetch = (url, { toEncode, reflect = false, ...opts }) =>
new PCancelable(async (resolve, reject, onCancel) => {
const req = got(url, {
Expand Down Expand Up @@ -62,7 +64,7 @@ const FETCH_MODE = { fetch, prerender }
const getFetchMode = (url, { prerender }) => {
if (prerender === false) return 'fetch'
if (prerender !== 'auto') return 'prerender'
return autoDomains.includes(parseDomain(url).domain) ? 'fetch' : 'prerender'
return autoDomains.includes(getDomain(url)) ? 'fetch' : 'prerender'
}

module.exports = async (
Expand All @@ -78,10 +80,9 @@ module.exports = async (
) => {
const toEncode = htmlEncode(encoding)
const targetFetchMode = fetchMode(url, { prerender })
const opts =
targetFetchMode === 'fetch'
? { toEncode, ...gotOptions }
: { toEncode, getBrowserless, gotOptions, ...puppeteerOpts }
const opts = targetFetchMode === 'fetch'
? { toEncode, ...gotOptions }
: { toEncode, getBrowserless, gotOptions, ...puppeteerOpts }

const time = timeSpan()
const { html, mode } = await FETCH_MODE[targetFetchMode](url, opts)
Expand Down

0 comments on commit 07e4184

Please sign in to comment.