Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit 086ecd1

Browse files
committed
logItem when bground func is set up + README + test
1 parent 8a6e08a commit 086ecd1

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The plugin can be found on [npm here](https://www.npmjs.com/package/@netlify/plu
4848
- [Preview Locally](#preview-locally)
4949
- [Custom Netlify Redirects](#custom-netlify-redirects)
5050
- [Custom Netlify Functions](#custom-netlify-functions)
51+
- [Background Functions](#background-functions)
5152
- [Using Netlify Identity](#using-netlify-identity)
5253
- [Caveats](#caveats)
5354
- [Fallbacks for Pages with `getStaticPaths`](#fallbacks-for-pages-with-getstaticpaths)
@@ -223,7 +224,12 @@ Currently, there is no support for redirects set in your `netlify.toml` file.
223224
### Custom Netlify Functions
224225

225226
`next-on-netlify` creates one Netlify Function for each of your
226-
SSR pages and API endpoints. It is currently not possible to create custom Netlify Functions. This feature is on our list to do.
227+
SSR pages and API endpoints. Currently, you can only create custom Netlify functions using [@netlify/plugin-nextjs](https://github.com/netlify/netlify-plugin-nextjs#custom-netlify-functions).
228+
229+
### Background Functions
230+
231+
If your Next.js API page/route ends in `-background`, it will be treated as a [Netlify background function](https://docs.netlify.com/functions/background-functions/).
232+
Note: background functions are only available on certain plans.
227233

228234
### Using Netlify Identity
229235

lib/helpers/setupNetlifyFunctionForPage.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
FUNCTION_TEMPLATE_PATH,
77
} = require("../config");
88
const getNetlifyFunctionName = require("./getNetlifyFunctionName");
9+
const { logItem } = require("./logger");
910

1011
// Create a Netlify Function for the page with the given file path
1112
const setupNetlifyFunctionForPage = ({
@@ -17,7 +18,13 @@ const setupNetlifyFunctionForPage = ({
1718
const functionName = getNetlifyFunctionName(filePath, isApiPage);
1819
const functionDirectory = join(functionsPath, functionName);
1920

20-
// Copy function template
21+
if (isApiPage && functionName.endsWith("-background")) {
22+
logItem(
23+
`👁 Setting up API page ${functionName} as a Netlify background function`
24+
);
25+
}
26+
27+
// Copy function templates
2128
const functionTemplateCopyPath = join(
2229
functionDirectory,
2330
`${functionName}.js`

tests/defaults.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ describe("API Pages", () => {
129129
join(functionsDir, "next_api_shows_params", "next_api_shows_params.js")
130130
)
131131
).toBe(true);
132+
expect(
133+
existsSync(
134+
join(
135+
functionsDir,
136+
"next_api_hello-background",
137+
"next_api_hello-background.js"
138+
)
139+
)
140+
).toBe(true);
132141
});
133142
});
134143

0 commit comments

Comments
 (0)