Skip to content

Commit d4a8856

Browse files
committed
Fix function timeout for API endpoint
As described in netlify/next-on-netlify#66 (comment)
1 parent dcc21b3 commit d4a8856

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pages/api/test.js

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import admin from "firebase-admin";
22

33
const test = async (req, res) => {
4+
// Get function context to avoid timeout
5+
// See: https://github.com/netlify/next-on-netlify/issues/66#issuecomment-719988804
6+
const functionContext = req?.functionContext;
7+
8+
// If we are currently in a Netlify function (deployed on netlify.app or
9+
// locally with netlify dev), do not wait for empty event loop.
10+
// See: https://stackoverflow.com/a/39215697/6451879
11+
// Skip during next dev.
12+
if (functionContext) {
13+
console.log("Setting callbackWaitsForEmptyEventLoop: false");
14+
functionContext.callbackWaitsForEmptyEventLoop = false;
15+
}
16+
17+
// Initialize firebase app
418
if (!admin.apps.length) {
519
admin.initializeApp({
620
credential: admin.credential.cert({

0 commit comments

Comments
 (0)