-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update the screenshot Lambda function (#20427)
* Replace vendored dependency with npm packages * Drop babel, run the code directly on node 10+ * Remove unneeded files * Use new dependency * Rewrite Add readme and manual tests for lambda function Co-authored-by: GatsbyJS Bot <mathews.kyle+gatsbybot@gmail.com>
- Loading branch information
1 parent
51d81e9
commit 242ff89
Showing
15 changed files
with
284 additions
and
335 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
yarn.lock | ||
lambda-package.zip | ||
lambda-dist | ||
lambda/screenshots |
39 changes: 0 additions & 39 deletions
39
packages/gatsby-transformer-screenshot/chrome/buildChrome.sh
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-44.4 MB
packages/gatsby-transformer-screenshot/chrome/headless_shell.tar.gz
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
# About | ||
|
||
This is the Lambda function that gatsby-transformer-screenshot uses to take screenshots. See [the plugin README](../README.md) for instructions on deploying this. | ||
|
||
## Manual testing | ||
|
||
The files in the `__manual_tests__` directory can be used to test locally or test the deployed version on AWS. | ||
|
||
Note that successful runs will cache the screenshot. Be sure to change the `SITE_URL` to re-test screenshot functionality. | ||
|
||
### Local | ||
|
||
To test the Puppeteer functionality locally: | ||
|
||
`TEST_WITH_LOCAL_FS=true SITE_URL=https://en.wikipedia.org/wiki/Wool node __manual-tests__/local-test.js` | ||
|
||
Screenshots will be saved to `./screenshots`. | ||
|
||
### Remote | ||
|
||
To test the function deployed at `<url to Lambda endpoint>`: | ||
|
||
`SCREENSHOT_ENDPOINT=<URL to Lambda endpoint> SITE_URL=https://en.wikipedia.org/wiki/Iron node __manual-tests__/remote-test.js` |
24 changes: 24 additions & 0 deletions
24
packages/gatsby-transformer-screenshot/lambda/__manual-tests__/local-test.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,24 @@ | ||
const thing = require(`../index`) | ||
const url = process.env.SITE_URL | ||
|
||
const start = async () => { | ||
const result = await thing.handler( | ||
{ | ||
body: `{"url":"${url}"}`, | ||
}, | ||
{ | ||
fail: err => { | ||
console.log(`error:`) | ||
console.log(err) | ||
}, | ||
succeed: res => { | ||
console.log(`success!`) | ||
console.log(res) | ||
}, | ||
} | ||
) | ||
|
||
return result | ||
} | ||
|
||
start() |
18 changes: 18 additions & 0 deletions
18
packages/gatsby-transformer-screenshot/lambda/__manual-tests__/remote-test.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,18 @@ | ||
const axios = require(`axios`) | ||
const SCREENSHOT_ENDPOINT = process.env.SCREENSHOT_ENDPOINT | ||
const url = process.env.SITE_URL | ||
|
||
const start = async () => { | ||
let screenshotResponse | ||
try { | ||
screenshotResponse = await axios.post(SCREENSHOT_ENDPOINT, { url }) | ||
const { status, data /* , headers */ } = screenshotResponse | ||
console.log(status) | ||
console.log(data) | ||
} catch (error) { | ||
console.log(error) | ||
console.log(screenshotResponse) | ||
} | ||
} | ||
|
||
start() |
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
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{ | ||
"dependencies": { | ||
"chrome-aws-lambda": "^2.0.1", | ||
"gatsby-core-utils": "^1.0.22", | ||
"puppeteer": "0.13.0", | ||
"tar": "^4.4.13" | ||
"puppeteer-core": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"aws-sdk": "^2.586.0" | ||
}, | ||
"keywords": [ | ||
"gatsby-plugin" | ||
] | ||
"keywords": [], | ||
"engines": { | ||
"node": ">=10.13.0" | ||
} | ||
} |
Oops, something went wrong.