This repository has been 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
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
sw-yx
committed
Mar 20, 2019
1 parent
26ecd50
commit dc51eb2
Showing
33 changed files
with
927 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
) | ||
|
||
func handler(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) { | ||
return &events.APIGatewayProxyResponse{ | ||
StatusCode: 200, | ||
Body: "Hello, World", | ||
}, nil | ||
} | ||
|
||
func main() { | ||
// Make the handler available for Remote Procedure Call by AWS Lambda | ||
lambda.Start(handler) | ||
} |
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,12 @@ | ||
// every object should have: | ||
// // a 'name' field that corresponds to a folder | ||
// // "description" is just what shows in the CLI but we use the name as the identifier | ||
// onComplete is optional. | ||
// priority is optional - for controlling what shows first in CLI | ||
module.exports = [ | ||
{ | ||
name: 'hello-world', | ||
priority: 1, | ||
description: 'Basic Hello World function in Golang' | ||
} | ||
] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,36 @@ | ||
const faunadb = require('faunadb') | ||
|
||
/* configure faunaDB Client with our secret */ | ||
const q = faunadb.query | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB_SERVER_SECRET | ||
}) | ||
|
||
/* export our lambda function as named "handler" export */ | ||
exports.handler = (event, context, callback) => { | ||
/* parse the string body into a useable JS object */ | ||
const data = JSON.parse(event.body) | ||
console.log('Function `todo-create` invoked', data) | ||
const todoItem = { | ||
data: data | ||
} | ||
/* construct the fauna query */ | ||
return client | ||
.query(q.Create(q.Ref('classes/todos'), todoItem)) | ||
.then(response => { | ||
console.log('success', response) | ||
/* Success! return the response with statusCode 200 */ | ||
return callback(null, { | ||
statusCode: 200, | ||
body: JSON.stringify(response) | ||
}) | ||
}) | ||
.catch(error => { | ||
console.log('error', error) | ||
/* Error! return the error with statusCode 400 */ | ||
return callback(null, { | ||
statusCode: 400, | ||
body: JSON.stringify(error) | ||
}) | ||
}) | ||
} |
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,32 @@ | ||
/* Import faunaDB sdk */ | ||
const faunadb = require('faunadb') | ||
|
||
function getId(urlPath) { | ||
return urlPath.match(/([^\/]*)\/*$/)[0] | ||
} | ||
|
||
const q = faunadb.query | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB_SERVER_SECRET | ||
}) | ||
|
||
exports.handler = (event, context, callback) => { | ||
const id = getId(event.path) | ||
console.log(`Function 'todo-delete' invoked. delete id: ${id}`) | ||
return client | ||
.query(q.Delete(q.Ref(`classes/todos/${id}`))) | ||
.then(response => { | ||
console.log('success', response) | ||
return callback(null, { | ||
statusCode: 200, | ||
body: JSON.stringify(response) | ||
}) | ||
}) | ||
.catch(error => { | ||
console.log('error', error) | ||
return callback(null, { | ||
statusCode: 400, | ||
body: JSON.stringify(error) | ||
}) | ||
}) | ||
} |
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,14 @@ | ||
exports.handler = async (event, context, callback) => { | ||
const { action } = event.queryStringParameters | ||
switch (action) { | ||
case 'create': | ||
return require('./create').handler(event, context, callback) | ||
case 'read': | ||
return require('./read').handler(event, context, callback) | ||
case 'update': | ||
return require('./update').handler(event, context, callback) | ||
case 'delete': | ||
return require('./delete').handler(event, context, callback) | ||
} | ||
return { statusCode: 500, body: 'unrecognized action ' + action } | ||
} |
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,20 @@ | ||
{ | ||
"name": "fauna-crud", | ||
"version": "1.0.0", | ||
"description": "netlify functions:create - CRUD functionality with Fauna DB", | ||
"main": "fauna-crud.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"netlify", | ||
"serverless", | ||
"js", | ||
"faunadb" | ||
], | ||
"author": "Netlify", | ||
"license": "MIT", | ||
"dependencies": { | ||
"faunadb": "^2.6.1" | ||
} | ||
} |
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,32 @@ | ||
/* Import faunaDB sdk */ | ||
const faunadb = require('faunadb') | ||
|
||
function getId(urlPath) { | ||
return urlPath.match(/([^\/]*)\/*$/)[0] | ||
} | ||
|
||
const q = faunadb.query | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB_SERVER_SECRET | ||
}) | ||
|
||
exports.handler = (event, context, callback) => { | ||
const id = getId(event.path) | ||
console.log(`Function 'todo-read' invoked. Read id: ${id}`) | ||
return client | ||
.query(q.Get(q.Ref(`classes/todos/${id}`))) | ||
.then(response => { | ||
console.log('success', response) | ||
return callback(null, { | ||
statusCode: 200, | ||
body: JSON.stringify(response) | ||
}) | ||
}) | ||
.catch(error => { | ||
console.log('error', error) | ||
return callback(null, { | ||
statusCode: 400, | ||
body: JSON.stringify(error) | ||
}) | ||
}) | ||
} |
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,33 @@ | ||
/* Import faunaDB sdk */ | ||
const faunadb = require('faunadb') | ||
|
||
function getId(urlPath) { | ||
return urlPath.match(/([^\/]*)\/*$/)[0] | ||
} | ||
|
||
const q = faunadb.query | ||
const client = new faunadb.Client({ | ||
secret: process.env.FAUNADB_SERVER_SECRET | ||
}) | ||
|
||
exports.handler = (event, context, callback) => { | ||
const data = JSON.parse(event.body) | ||
const id = getId(event.path) | ||
console.log(`Function 'todo-update' invoked. update id: ${id}`) | ||
return client | ||
.query(q.Update(q.Ref(`classes/todos/${id}`), { data })) | ||
.then(response => { | ||
console.log('success', response) | ||
return callback(null, { | ||
statusCode: 200, | ||
body: JSON.stringify(response) | ||
}) | ||
}) | ||
.catch(error => { | ||
console.log('error', error) | ||
return callback(null, { | ||
statusCode: 400, | ||
body: JSON.stringify(error) | ||
}) | ||
}) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
src/functions-templates/js/protected-function/protected-function.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,23 @@ | ||
exports.handler = async (event, context) => { | ||
console.log('protected function!') | ||
// Reading the context.clientContext will give us the current user | ||
const claims = context.clientContext && context.clientContext.user | ||
console.log('user claims', claims) | ||
|
||
if (!claims) { | ||
console.log('No claims! Begone!') | ||
return { | ||
statusCode: 401, | ||
body: JSON.stringify({ | ||
data: 'NOT ALLOWED' | ||
}) | ||
} | ||
} | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
data: 'auth true' | ||
}) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,19 @@ | ||
{ | ||
"name": "set-cookie", | ||
"version": "1.0.0", | ||
"description": "netlify functions:create - set a cookie with your Netlify Function", | ||
"main": "set-cookie", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"netlify", | ||
"serverless", | ||
"js" | ||
], | ||
"author": "Netlify", | ||
"license": "MIT", | ||
"dependencies": { | ||
"cookie": "^0.3.1" | ||
} | ||
} |
Oops, something went wrong.