Skip to content

Commit b060c80

Browse files
authored
Merge pull request #1 from samestrin/development
Development
2 parents d995c6d + 7cd9bb8 commit b060c80

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# url-shortening-api-netlify-edge-supabase
1+
# url-shortening-api-netlify-edge-supabase
2+
3+
url-shortening-api-netlify-edge-supabase is a URL shortener service. It is a serverless application that provides URL shortening and retrieval functionalities. Utilizing Netlify Edge Functions and Supabase, a cloud-based database, the application offers an efficient and scalable solution for creating short URLs that redirect to the original, longer URLs.
4+
5+
This replaces the legacy [url-shortening-api-netlify-supabase](https://github.com/samestrin/url-shortening-api-netlify-supabase) project.

netlify.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
path = "/latest"
1717
function = "latest"
1818

19+
[[edge_functions]]
20+
path = "/version"
21+
function = "version"
22+
1923
[[edge_functions]]
2024
path = "/*"
2125
function = "redirect"

netlify/edge-functions/version.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import packageJson from "../../package.json" assert { type: "json" };
2+
3+
export default async (request: Request): Promise<Response> => {
4+
try {
5+
const { name, description, author, homepage, version } = packageJson;
6+
7+
const response = {
8+
name,
9+
version,
10+
description,
11+
author,
12+
homepage,
13+
};
14+
15+
return new Response(JSON.stringify(response), {
16+
status: 200,
17+
headers: {
18+
"Content-Type": "application/json",
19+
},
20+
});
21+
} catch (error) {
22+
console.error("Error reading package.json:", error);
23+
return new Response(
24+
JSON.stringify({
25+
error: "Internal server error",
26+
details: error.message,
27+
}),
28+
{ status: 500 }
29+
);
30+
}
31+
};
32+
33+
export const config = { path: "/version" };

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "url-shortening-api-netlify-edge-supabase",
33
"version": "0.0.1",
4-
"description": "",
4+
"description": "url-shortening-api-netlify-edge-supabase is a URL shortener service using Netlify Edge Functions and the Supabase REST API.",
55
"main": "public/index.html",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"

supabase.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# url-shortening-api-netlify-edge-supabase
2+
3+
## Supabase Setup
4+
5+
Setting up Supabase for your project involves a few key steps, from creating an account to initializing your database and integrating it with your application. Here’s a detailed walkthrough:
6+
7+
**Sign Up and Create a New Project**:
8+
9+
Visit [Supabase](https://supabase.io/) and sign up for a new account if you don't already have one.
10+
11+
Once logged in, create a new project by specifying a project name, database password, and the region closest to your users to minimize latency.
12+
13+
**Project Setup**:
14+
15+
After your project is created, which might take a few minutes, you will be redirected to the project dashboard.
16+
17+
Your project’s URL (`SUPABASE_URL`) and anon key (`SUPABASE_ANON_KEY`), which are required for connecting your application to Supabase, can be found under the `Settings` -> `API` section of your Supabase project dashboard.
18+
19+
## Database Configuration
20+
21+
Create Tables: Use the SQL editor in Supabase to create the necessary tables for your application. For the URL shortener, you’ll need a table to store URLs with columns for the short URL and the original URL.
22+
23+
```sql
24+
CREATE TABLE urls (
25+
id SERIAL PRIMARY KEY,
26+
short_url VARCHAR(255) UNIQUE NOT NULL,
27+
long_url VARCHAR(2048) NOT NULL
28+
);
29+
```
30+
31+
**Row Level Security (RLS)**:
32+
33+
Enable RLS for your tables to ensure that your data is secure and accessible only according to your specified policies.

0 commit comments

Comments
 (0)