Created
April 29, 2018 16:02
-
-
Save ohmpzz/390658db710e4b9c7cfc3eb7e0f5a3d5 to your computer and use it in GitHub Desktop.
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
| const admin = require('firebase-admin'); | |
| const CryptoJS = require("crypto-js") | |
| const firebaseConfig = require('./config/firebase') | |
| const express = require('express') | |
| const cors = require('cors') | |
| const bodyParser = require('body-parser') | |
| const app = express() | |
| app.use(cors()) | |
| app.use(bodyParser.json()) | |
| app.use(bodyParser.urlencoded({ extended: true})) | |
| app.post('/secure', (req, res) => { | |
| console.log('[starting secure-chat]: ..') | |
| const secretKey = 'this is a secret key' | |
| const ciphertext = req.body.payload | |
| const bytes = CryptoJS.AES.decrypt(ciphertext, secretKey) | |
| const plaintext = bytes.toString(CryptoJS.enc.Utf8) | |
| console.log('[secure-chat]: plaintext => ', plaintext) | |
| admin.firestore() | |
| .collection('secure-chat').add({msg: ciphertext}) | |
| .then(ref => { | |
| console.log('[secure-chat(added)]: ', ciphertext) | |
| res.json({cb: ref}) | |
| }) | |
| .catch(err => res.json({cb: 'err'})) | |
| }) | |
| app.post('/unsecure', (req, res) => { | |
| console.log('[starting unsecure-chat]: ..') | |
| const plaintext = req.body.payload | |
| admin.firestore() | |
| .collection('unsecure-chat').add({msg: plaintext}) | |
| .then(ref => { | |
| console.log('[unsecure-chat(added)]: ', plaintext) | |
| res.json({cb: ref}) | |
| }) | |
| .catch(err => res.json({cb: 'err'})) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment