-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
swyx
committed
Dec 6, 2018
1 parent
f4976e1
commit 42d3c35
Showing
5 changed files
with
38 additions
and
4 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
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
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,25 @@ | ||
// example of async handler using async-await | ||
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311 | ||
|
||
import fetch from 'node-fetch'; | ||
export async function handler(event, context) { | ||
try { | ||
const response = await fetch('https://api.chucknorris.io/jokes/random'); | ||
if (!response.ok) { | ||
// NOT res.status >= 200 && res.status < 300 | ||
return { statusCode: response.status, body: response.statusText }; | ||
} | ||
const data = await response.json(); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ msg: data.value }) | ||
}; | ||
} catch (err) { | ||
console.log(err); // output to netlify function log | ||
return { | ||
statusCode: 500, | ||
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err) | ||
}; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6046,6 +6046,11 @@ no-case@^2.2.0: | |
dependencies: | ||
lower-case "^1.1.1" | ||
|
||
node-fetch@^2.3.0: | ||
version "2.3.0" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5" | ||
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA== | ||
|
||
[email protected]: | ||
version "0.7.5" | ||
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df" | ||
|