-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add .ts files to prettier config (#6204)
* chore: add .ts files to prettier config * style: lint
- Loading branch information
1 parent
5c61169
commit d93412a
Showing
30 changed files
with
188 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import type { Context } from "https://edge.netlify.com"; | ||
import type { Context } from 'https://edge.netlify.com' | ||
|
||
export default async (request: Request, context: Context) => { | ||
// look for existing "test_bucket" cookie | ||
const bucketName = "test_bucket"; | ||
const bucket = context.cookies.get(bucketName); | ||
const bucketName = 'test_bucket' | ||
const bucket = context.cookies.get(bucketName) | ||
|
||
// return here if we find a cookie | ||
if (bucket) { | ||
return new Response(`Welcome back! You were assigned ${bucketName} **${bucket}** when you last visited the site!`); | ||
return new Response(`Welcome back! You were assigned ${bucketName} **${bucket}** when you last visited the site!`) | ||
} | ||
|
||
// if no "test_bucket" cookie is found, assign the user to a bucket | ||
// in this example we're using two buckets (a, b) with an equal weighting of 50/50 | ||
const weighting = 0.5; | ||
const weighting = 0.5 | ||
|
||
// get a random number between (0-1) | ||
// this is a basic example and you may want to experiment | ||
const random = Math.random(); | ||
const newBucketValue = random <= weighting ? "a" : "b"; | ||
const random = Math.random() | ||
const newBucketValue = random <= weighting ? 'a' : 'b' | ||
|
||
// set the new "test_bucket" cookie | ||
context.cookies.set({ | ||
name: bucketName, | ||
value: newBucketValue, | ||
}); | ||
}) | ||
|
||
return new Response( | ||
`Congratulations! You have been assigned ${bucketName} **${newBucketValue}**. View your browser cookies to check it out!`, | ||
); | ||
}; | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import type { Context } from "https://edge.netlify.com"; | ||
import type { Context } from 'https://edge.netlify.com' | ||
|
||
export default async (request: Request, context: Context) => { | ||
return Response.json({ hello: "world", location: context.geo.city }); | ||
}; | ||
export default async (request: Request, context: Context) => | ||
Response.json({ hello: 'world', location: context.geo.city }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import type { Context } from "https://edge.netlify.com"; | ||
import type { Context } from 'https://edge.netlify.com' | ||
|
||
export default async (request: Request, context: Context) => { | ||
console.log(`There was a request from ${context.geo.city} to ${request.url}`); | ||
console.log(`There was a request from ${context.geo.city} to ${request.url}`) | ||
|
||
return new Response("The request to this URL was logged", { | ||
headers: { "content-type": "text/html" }, | ||
}); | ||
}; | ||
return new Response('The request to this URL was logged', { | ||
headers: { 'content-type': 'text/html' }, | ||
}) | ||
} |
18 changes: 9 additions & 9 deletions
18
src/functions-templates/typescript/scheduled-function/{{name}}.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { schedule } from '@netlify/functions'; | ||
import { schedule } from '@netlify/functions' | ||
|
||
// To learn about scheduled functions and supported cron extensions, | ||
// To learn about scheduled functions and supported cron extensions, | ||
// see: https://ntl.fyi/sched-func | ||
export const handler = schedule("@hourly", async (event) => { | ||
const eventBody = JSON.parse(event.body); | ||
console.log(`Next function run at ${eventBody.next_run}.`); | ||
export const handler = schedule('@hourly', async (event) => { | ||
const eventBody = JSON.parse(event.body) | ||
console.log(`Next function run at ${eventBody.next_run}.`) | ||
|
||
return { | ||
statusCode: 200 | ||
}; | ||
}); | ||
return { | ||
statusCode: 200, | ||
} | ||
}) |
30 changes: 15 additions & 15 deletions
30
src/functions-templates/typescript/set-cookies/{{name}}.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
import type { Context } from "https://edge.netlify.com"; | ||
import type { Context } from 'https://edge.netlify.com' | ||
|
||
export default async (request: Request, context: Context) => { | ||
const url = new URL(request.url); | ||
const url = new URL(request.url) | ||
|
||
switch (url.searchParams.get("action")) { | ||
case "set": | ||
switch (url.searchParams.get('action')) { | ||
case 'set': | ||
context.cookies.set({ | ||
name: "action", | ||
value: "hello", | ||
}); | ||
name: 'action', | ||
value: 'hello', | ||
}) | ||
|
||
return new Response('Cookie value has been set. Reload this page without the "action" parameter to see it.'); | ||
return new Response('Cookie value has been set. Reload this page without the "action" parameter to see it.') | ||
|
||
case "clear": | ||
context.cookies.delete("action"); | ||
case 'clear': | ||
context.cookies.delete('action') | ||
|
||
return new Response( | ||
'Cookie value has been cleared. Reload this page without the "action" parameter to see the new state.', | ||
); | ||
) | ||
} | ||
|
||
const value = context.cookies.get("action"); | ||
const value = context.cookies.get('action') | ||
const message = value | ||
? `Cookie value is "${value}". You can clear it by using "?action=clear".` | ||
: 'Cookie has not been set. You can do so by adding "?action=set" to the URL.'; | ||
: 'Cookie has not been set. You can do so by adding "?action=set" to the URL.' | ||
|
||
return new Response(message); | ||
}; | ||
return new Response(message) | ||
} |
6 changes: 3 additions & 3 deletions
6
src/functions-templates/typescript/set-req-header/{{name}}.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { Context } from "https://edge.netlify.com"; | ||
import type { Context } from 'https://edge.netlify.com' | ||
|
||
export default async (request: Request, context: Context) => { | ||
request.headers.set("X-Your-Custom-Header", "Your custom header value"); | ||
}; | ||
request.headers.set('X-Your-Custom-Header', 'Your custom header value') | ||
} |
Oops, something went wrong.
d93412a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📊 Benchmark results