Skip to content

Commit

Permalink
Fix function timeout for API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnWoelm committed Oct 31, 2020
1 parent dcc21b3 commit d4a8856
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pages/api/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import admin from "firebase-admin";

const test = async (req, res) => {
// Get function context to avoid timeout
// See: https://github.com/netlify/next-on-netlify/issues/66#issuecomment-719988804
const functionContext = req?.functionContext;

// If we are currently in a Netlify function (deployed on netlify.app or
// locally with netlify dev), do not wait for empty event loop.
// See: https://stackoverflow.com/a/39215697/6451879
// Skip during next dev.
if (functionContext) {
console.log("Setting callbackWaitsForEmptyEventLoop: false");
functionContext.callbackWaitsForEmptyEventLoop = false;
}

// Initialize firebase app
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert({
Expand Down

0 comments on commit d4a8856

Please sign in to comment.