This repository was archived by the owner on Sep 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
add working basic templates for netlify functions:create #22
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
"ascii-table": "0.0.9", | ||
"get-port": "^4.1.0", | ||
"http-proxy": "^1.17.0", | ||
"inquirer": "^6.2.2", | ||
"netlify": "ssh+git://[email protected]:netlify/js-client-private", | ||
"netlify-rules-proxy": "git+ssh://[email protected]/netlify/netlify-rules-proxy.git", | ||
"static-dev-server": "^1.0.0", | ||
|
This file contains hidden or 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 hidden or 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,11 @@ | ||
## note to devs | ||
|
||
place new templates here and our CLI will pick it up. currently only works for single file `.js` templates. | ||
|
||
## why place it in this separate folder | ||
|
||
we dont colocate this inside `src/commands/functions` because oclif will think it's a new command. | ||
|
||
## future dev thoughts | ||
|
||
we will want a way to scale this to TS and Go as well. |
This file contains hidden or 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,12 @@ | ||
async function hello() { | ||
return Promise.resolve('Hello, World') | ||
} | ||
|
||
exports.handler = async function(event, context) { | ||
try { | ||
const body = await hello() | ||
return { statusCode: 200, body } | ||
} catch (err) { | ||
return { statusCode: 500, body: err.toString() } | ||
} | ||
} |
This file contains hidden or 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,22 @@ | ||
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) | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.