Skip to content

Commit

Permalink
Merge pull request #277 from vivliostyle/update-deps-in-functions
Browse files Browse the repository at this point in the history
update deps and nodejs ver in /functions
  • Loading branch information
MurakamiShinyu authored Sep 4, 2023
2 parents 3488946 + 967ae09 commit ff64112
Show file tree
Hide file tree
Showing 5 changed files with 1,262 additions and 1,052 deletions.
2 changes: 1 addition & 1 deletion functions/.node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.15.3
18
14 changes: 7 additions & 7 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
"start": "npm run shell"
},
"dependencies": {
"@google-cloud/pubsub": "^1.7.3",
"@octokit/webhooks": "^7.2.0",
"firebase-admin": "^8.10.0",
"firebase-functions": "^3.6.0"
"@google-cloud/pubsub": "^4.0.2",
"@octokit/webhooks": "^12.0.3",
"firebase-admin": "^11.10.1",
"firebase-functions": "^4.4.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.1",
"typescript": "^3.8.3"
"firebase-functions-test": "^3.1.0",
"typescript": "^5.1.6"
},
"main": "lib/index.js",
"engines": {
"node": "14"
"node": "18"
},
"private": true
}
9 changes: 4 additions & 5 deletions functions/src/buildPdf/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as admin from 'firebase-admin';
import {initializeApp, getApps} from 'firebase-admin/app';
import {getFirestore} from 'firebase-admin/firestore';
import * as functions from 'firebase-functions';
import { PubSub } from '@google-cloud/pubsub';

if (!admin.apps.length) {
admin.initializeApp(functions.config().firebase);
}
const firestore = admin.firestore();
if (!getApps().length) initializeApp(functions.config().firebase);
const firestore = getFirestore();

const publishMessage = async(topicName:string, data:any) => {
const pubSubClient = new PubSub();
Expand Down
26 changes: 17 additions & 9 deletions functions/src/webhookHandler/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as admin from 'firebase-admin';
import {initializeApp, getApps} from 'firebase-admin/app';
import {getFirestore} from 'firebase-admin/firestore';
import * as functions from 'firebase-functions';
import * as WebhooksApi from '@octokit/webhooks';
import {Webhooks, createNodeMiddleware} from '@octokit/webhooks';

if (!admin.apps.length) {
admin.initializeApp(functions.config().firebase);
}
const firestore = admin.firestore();
if (!getApps().length) initializeApp(functions.config().firebase);
const firestore = getFirestore();

const getEnv = (key: string) =>
process.env.FIREBASE_CONFIG
Expand All @@ -14,7 +13,7 @@ const getEnv = (key: string) =>
]
: process.env[`GH_APP_${key}`];

const webhooks = new WebhooksApi({
const webhooks = new Webhooks({
secret: getEnv('WEBHOOK_SECRET'),
});

Expand All @@ -33,11 +32,20 @@ webhooks.on('installation', async (event) => {
}
});

webhooks.on('error', (error) => {
webhooks.onError((error) => {
console.log(error.stack);
});

// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript

export const webhookHandler = functions.https.onRequest(webhooks.middleware);
const middleware = createNodeMiddleware(webhooks, {path: '/'});

export const webhookHandler = functions.https.onRequest(async (req, res) => {
if (typeof req.body === 'object') {
req.body = JSON.stringify(req.body);
}
if (await middleware(req, res)) return;
res.writeHead(404);
res.end();
});
Loading

1 comment on commit ff64112

@vercel
Copy link

@vercel vercel bot commented on ff64112 Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.