Skip to content

Commit 534b42c

Browse files
bartvenemanBart Veneman
andauthored
update deps, fix normalizeUrl issue (projectwallace#33)
* update deps, fix normalizeUrl issue * rm unsupported vercel config option * rm unsupported vercel config option * moar normalizing Co-authored-by: Bart Veneman <bart.veneman@drukwerkdeal.nl>
1 parent 3a7f04c commit 534b42c

File tree

6 files changed

+609
-616
lines changed

6 files changed

+609
-616
lines changed

.github/funding.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
github: []
1+
github: bartveneman
22
patreon: bartveneman
33
open_collective: projectwallace
4-
custom: ['https://www.projectwallace.com/sponsor', 'https://www.paypal.me/bartveneman']
4+
custom: [https://www.projectwallace.com/sponsor', 'https://www.paypal.me/bartveneman']

_chromium.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,20 @@
22

33
const puppeteer = require('puppeteer-core')
44
const chrome = require('chrome-aws-lambda')
5-
const exePath =
6-
process.platform === 'win32' ?
7-
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe' :
8-
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
5+
const normalizeUrl = require('normalize-url')
96

10-
const isDev = process.env.NOW_REGION === 'dev1'
11-
12-
async function getOptions() {
13-
if (isDev) {
14-
return {
15-
args: [],
16-
executablePath: exePath,
17-
headless: true
18-
}
19-
}
20-
21-
return {
7+
exports.extractCss = async url => {
8+
const browser = await puppeteer.launch({
229
args: chrome.args,
2310
executablePath: await chrome.executablePath,
2411
headless: chrome.headless
25-
}
26-
}
27-
28-
exports.extractCss = async url => {
29-
const options = await getOptions()
30-
const browser = await puppeteer.launch(options)
12+
})
3113
const page = await browser.newPage()
3214

3315
// Start CSS coverage. This is the meat and bones of this module
3416
await page.coverage.startCSSCoverage().catch(() => {})
3517

18+
url = normalizeUrl(url, {stripWWW: false})
3619
const response = await page.goto(url, {waitUntil: 'networkidle0'})
3720

3821
// Make sure that we only try to extract CSS from valid pages.

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {extractCss} = require('./_chromium')
55

66
const cssCache = new LRU({
77
max: 500,
8-
maxAge: 3 * 60 * 1000 // 3 minutes
8+
maxAge: 60 * 1000 // 60 seconds
99
})
1010

1111
module.exports = async (req, res) => {
@@ -16,7 +16,7 @@ module.exports = async (req, res) => {
1616
res.setHeader('Content-Type', 'application/json')
1717

1818
return res.send({
19-
message: 'The provided URL is not valid'
19+
message: `The provided URL \`${url}\` is not valid`
2020
})
2121
}
2222

now.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
{ "src": "public/*", "use": "@now/static" },
77
{
88
"src": "index.js",
9-
"use": "@now/node",
10-
"config": { "maxLambdaSize": "40mb" }
9+
"use": "@now/node"
1110
}
1211
],
1312
"routes": [
1413
{ "src": "/", "dest": "/public/index.html" },
1514
{ "src": "/(.+)", "dest": "/index.js" }
16-
],
17-
"regions": ["all"]
15+
]
1816
}

0 commit comments

Comments
 (0)