Skip to content

Commit 40dafd5

Browse files
authored
feat: update function templates to v2 (#6939)
* feat: hello-world js example to mjs * feat: remove identity example * feat: remove sanity templates * feat: scheduled function to esm * feat: remove submission-create example because 3rd party docs out of date * feat: typescript hello world and make js same * feat: typescript scheduled function * test: update tests
1 parent 4e668f2 commit 40dafd5

File tree

21 files changed

+58
-326
lines changed

21 files changed

+58
-326
lines changed

.eslintrc.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = {
7070
},
7171
// Example functions
7272
{
73-
files: ['functions-templates/**/*.js'],
73+
files: ['functions-templates/**/*.mjs', 'functions-templates/**/*.mts'],
7474
rules: {
7575
'require-await': 0,
7676
'import/no-unresolved': 0,
@@ -80,6 +80,8 @@ module.exports = {
8080
'no-undef': 0,
8181
'no-unused-vars': 0,
8282
'arrow-body-style': 0,
83+
'n/no-unsupported-features/node-builtins': 0,
84+
camelcase: 0,
8385
},
8486
parserOptions: {
8587
sourceType: 'module',

functions-templates/javascript/hello-world/{{name}}.js

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Docs on request and context https://docs.netlify.com/functions/build/#code-your-function-2
2+
export default (request, context) => {
3+
try {
4+
const url = new URL(request.url)
5+
const subject = url.searchParams.get('name') || 'World'
6+
7+
return new Response(`Hello ${subject}`)
8+
} catch (error) {
9+
return new Response(error.toString(), {
10+
status: 500,
11+
})
12+
}
13+
}

functions-templates/javascript/identity-signup/.netlify-function-template.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

functions-templates/javascript/identity-signup/{{name}}.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

functions-templates/javascript/sanity-create/.netlify-function-template.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

functions-templates/javascript/sanity-create/package.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

functions-templates/javascript/sanity-create/{{name}}.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

functions-templates/javascript/sanity-groq/.netlify-function-template.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

functions-templates/javascript/sanity-groq/package.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

functions-templates/javascript/sanity-groq/{{name}}.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

functions-templates/javascript/scheduled-function/{{name}}.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// To learn about scheduled functions and supported cron extensions,
2+
// see: https://ntl.fyi/sched-func
3+
export default async (req) => {
4+
const { next_run } = await req.json()
5+
6+
console.log('Received event! Next invocation at:', next_run)
7+
}
8+
9+
export const config = {
10+
schedule: '@hourly',
11+
}

functions-templates/javascript/submission-created/.netlify-function-template.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

functions-templates/javascript/submission-created/package.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

functions-templates/javascript/submission-created/{{name}}.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Context } from '@netlify/functions'
2+
3+
export default (request: Request, context: Context) => {
4+
try {
5+
const url = new URL(request.url)
6+
const subject = url.searchParams.get('name') || 'World'
7+
8+
return new Response(`Hello ${subject}`)
9+
} catch (error) {
10+
return new Response(error.toString(), {
11+
status: 500,
12+
})
13+
}
14+
}

functions-templates/typescript/hello-world/{{name}}.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Config } from "@netlify/functions"
2+
3+
export default async (req: Request) => {
4+
const { next_run } = await req.json()
5+
6+
console.log("Received event! Next invocation at:", next_run)
7+
}
8+
9+
export const config: Config = {
10+
schedule: "@hourly"
11+
}

0 commit comments

Comments
 (0)