Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // middleware.js
- const functions = require('firebase-functions');
- import * as crypto from 'crypto';
- export const auth = (req, res, next) => {
- let hash = crypto.createHash('sha512');
- hash.update(config.starling.key + req.rawBody));
- req.hasha = hash.digest('base64');
- // req.hasha is different from req.header('X-Hook-Signature')
- next();
- }
- import * as functions from 'firebase-functions';
- import * as express from 'express';
- import * as cors from 'cors';
- import * as middleware from './middleware';
- import bodyParser = require('body-parser');
- const app = express();
- app.use(cors({ origin: true }));
- app.use(bodyParser.json());
- app.use(middleware.auth);
- // Endpoints removed for brevity
- export const hooks = functions.https.onRequest(app);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement