Skip to content

Commit 82bb1c8

Browse files
committed
Fix function timeout when using firebase
See: https://stackoverflow.com/a/39215697/6451879
1 parent 6982b63 commit 82bb1c8

File tree

4 files changed

+223
-2
lines changed

4 files changed

+223
-2
lines changed

package-lock.json

+189
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
"react": "^17.0.1",
1111
"react-dom": "^17.0.1"
1212
},
13-
"devDependencies": {},
13+
"devDependencies": {
14+
"patch-package": "^6.2.2"
15+
},
1416
"scripts": {
17+
"postinstall": "patch-package",
1518
"dev": "next",
1619
"build": "next build",
1720
"postbuild": "next-on-netlify",

pages/test.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@ const TestPage = (props) => (
99
</>
1010
);
1111

12-
export async function getServerSideProps() {
12+
export async function getServerSideProps(context) {
13+
// Get function context
14+
const functionContext = context?.req?.functionContext;
15+
16+
// If we are currently in a Netlify function (deployed on netlify.app or
17+
// locally with netlify dev), do not wait for empty event loop.
18+
// See: https://stackoverflow.com/a/39215697/6451879
19+
// Skip during next dev.
20+
if (functionContext) {
21+
console.log("Setting callbackWaitsForEmptyEventLoop: false");
22+
functionContext.callbackWaitsForEmptyEventLoop = false;
23+
}
24+
1325
// Configuration for firebase
1426
const firebaseConfig = {
1527
apiKey: "AIzaSyBre20U7moSMgS5pCKSJsde2AIcssegRys",

patches/next-aws-lambda+2.5.0.patch

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/node_modules/next-aws-lambda/index.js b/node_modules/next-aws-lambda/index.js
2+
index f8daeb9..9085de7 100644
3+
--- a/node_modules/next-aws-lambda/index.js
4+
+++ b/node_modules/next-aws-lambda/index.js
5+
@@ -1,7 +1,11 @@
6+
const reqResMapper = require("./lib/compatLayer");
7+
8+
-const handlerFactory = page => (event, _context, callback) => {
9+
+const handlerFactory = page => (event, context, callback) => {
10+
const { req, res, responsePromise } = reqResMapper(event, callback);
11+
+
12+
+ // Make Netlify Function context available on request object
13+
+ req.functionContext = context
14+
+
15+
if (page.render instanceof Function) {
16+
// Is a React component
17+
page.render(req, res);

0 commit comments

Comments
 (0)