Skip to content

Commit 7690b85

Browse files
committed
Added Comments to Edge Functions
1 parent 4e56190 commit 7690b85

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

netlify/edge-functions/count.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import { headers } from "./headers.ts";
22
import handler from "./utils.ts";
33
const { fetchFromSupabase } = handler();
44

5+
/**
6+
* Counts the number of URLs stored in Supabase.
7+
*
8+
* @param request - The incoming HTTP request.
9+
* @returns The number of URLs in the Supabase database or an error message.
10+
* @throws If an error occurs while fetching the count from Supabase.
11+
*
12+
* @example
13+
* // Example usage
14+
* curl -X GET https://your-api-url/count
15+
*/
516
export default async (request: Request): Promise<Response> => {
617
try {
718
const response = await fetchFromSupabase("urls?select=id", {

netlify/edge-functions/headers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
/**
2+
* Common HTTP headers used in responses.
3+
*
4+
* @returns An object containing common HTTP headers.
5+
*
6+
* @example
7+
* // Example usage
8+
* const headers = getHeaders();
9+
* fetch('/api', { headers });
10+
*/
11+
112
export const headers = {
2-
'Access-Control-Allow-Origin': '*',
3-
'Access-Control-Allow-Methods': '*',
4-
'Access-Control-Allow-Headers': '*',
5-
'Access-Control-Max-Age': '86400',
6-
'Content-Type': 'application/json',
13+
"Access-Control-Allow-Origin": "*",
14+
"Access-Control-Allow-Methods": "*",
15+
"Access-Control-Allow-Headers": "*",
16+
"Access-Control-Max-Age": "86400",
17+
"Content-Type": "application/json",
718
};
819
export default () => headers;

netlify/edge-functions/latest.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ import handler from "./utils.ts";
33
const urlBase = Deno.env.get("URL_BASE") ? Deno.env.get("URL_BASE") : "";
44
const { fetchFromSupabase } = handler();
55

6+
/**
7+
* Retrieves the latest URLs stored in Supabase.
8+
*
9+
* @param request - The incoming HTTP request.
10+
* @returns The latest URLs from the Supabase database or an error message.
11+
* @throws If an error occurs while fetching the latest URLs from Supabase.
12+
*
13+
* @example
14+
* // Example usage
15+
* curl -X GET "https://your-api-url/latest?count=5"
16+
*/
617
export default async (request: Request): Promise<Response> => {
718
console.log("here");
819
try {

netlify/edge-functions/redirect.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import handler from "./utils.ts";
22
const { fetchFromSupabase } = handler();
33

4+
/**
5+
* Redirects to the long URL associated with the given short URL.
6+
*
7+
* @param request - The incoming HTTP request.
8+
* @returns A redirection response to the long URL or an error message.
9+
* @throws If an error occurs while fetching the long URL from Supabase.
10+
*
11+
* @example
12+
* // Example usage
13+
* curl -X GET https://your-api-url/shortUrl
14+
*/
415
export default async (request: Request): Promise<Response> => {
516
try {
617
const shortUrl = new URL(request.url).pathname.replace("/", "");

netlify/edge-functions/version.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
import packageJson from "../../package.json" assert { type: "json" };
22

3+
/**
4+
* Retrieves the current version of the API.
5+
*
6+
* @param request - The incoming HTTP request.
7+
* @returns A response containing the API version information or an error message.
8+
* @throws If an error occurs while reading the package.json file.
9+
*
10+
* @example
11+
* // Example usage
12+
* curl -X GET https://your-api-url/version
13+
*/
314
export default async (request: Request): Promise<Response> => {
415
try {
516
const { name, description, author, homepage, version } = packageJson;

0 commit comments

Comments
 (0)