-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
50 lines (46 loc) · 1.11 KB
/
Copy pathfunction.js
File metadata and controls
50 lines (46 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { getTransformStream } from "@probot/pino";
import pino from "pino";
import { createNodeMiddleware, createProbot } from "probot";
import app from "./app.js";
if (process.env.PRIVATE_KEY_BASE64) {
process.env.PRIVATE_KEY = Buffer.from(
process.env.PRIVATE_KEY_BASE64,
"base64"
).toString("utf8");
}
const log = pino(
{
transport: {
target: "cloud-pine",
options: {
cloudLoggingOptions: {
skipInit: true,
sync: true,
},
},
},
},
getTransformStream()
);
// Create middleware with path set to root
const middleware = createNodeMiddleware(app, {
probot: createProbot({ log }),
webhooksPath: "/", // Set path to root to match Cloud Function URL
});
export const probotApp = (req, res) => {
try {
middleware(req, res, () => {
if (!res.headersSent) {
res.writeHead(404);
res.end();
}
});
} catch (err) {
// Custom error handling
console.error("Unhandled error in Probot middleware:", err);
if (!res.headersSent) {
res.writeHead(500);
res.end("Internal Server Error");
}
}
};