Created
May 24, 2019 15:55
-
-
Save apotox/472e9be6585c675c89fcf1aec5438358 to your computer and use it in GitHub Desktop.
lambda function for Netlify serverless
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
import * as admin from 'firebase-admin'; | |
//global.self = {fetch: require('node-fetch')} | |
var serviceAccount = { | |
//..... | |
} | |
const app = admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: "https://marine-potion-230514.firebaseio.com", | |
}) | |
exports.handler = async (event, context,)=>{ | |
const note = event.queryStringParameters.note || "no text"; | |
try{ | |
let ref = await app.database().ref("notes").push().set({note}) | |
return { | |
statusCode: 200, | |
body: `new note contains ${note}` | |
} | |
}catch(err){ | |
return { | |
statusCode: 200, | |
body: `err ${err.message}` | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment