Skip to content

Commit

Permalink
Adding support for /registerQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Dec 19, 2017
1 parent b19fb7f commit cce391a
Show file tree
Hide file tree
Showing 6 changed files with 1,580 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,6 +7,7 @@

# dependencies
/node_modules
/functions/node_modules

# IDEs and editors
/.idea
Expand Down
4 changes: 4 additions & 0 deletions firebase.json
Expand Up @@ -8,6 +8,10 @@
],
"rewrites": [
{
"source": "/registerQuery",
"function": "registerQuery"
},
{
"source": "**",
"destination": "/index.html"
}
Expand Down
15 changes: 15 additions & 0 deletions functions/index.js
@@ -0,0 +1,15 @@
const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.registerQuery = functions.https.onRequest((req, res) => {
const original = req.query.q;
admin.database().ref('/queries').push({
query: original,
timestamp: new Date().toUTCString(),
}).then(snapshot => {
console.log('wrote query to ' + snapshot.ref);
res.status(200).end();
});
});

0 comments on commit cce391a

Please sign in to comment.