manifold/functions/src/call-cloud-function.ts

18 lines
476 B
TypeScript
Raw Normal View History

2021-12-18 02:12:58 +00:00
import * as admin from 'firebase-admin'
import fetch from './fetch'
export const callCloudFunction = (functionName: string, data: {} = {}) => {
const projectId = admin.instanceId().app.options.projectId
let url = `https://us-central1-${projectId}.cloudfunctions.net/${functionName}`
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ data }),
}).then((response) => response.json())
}