This is URL Shortener application ran by Appwrite cloud function., on Appwrite platform.
This project is part of Appwrites Lightning Hackathon.
Currently working demo: On this link
This project is a simple URL Shortener service.
It contains a form with URL and Alias inputs.
In URL input you add your URL you want shorten.
In Alias input you write something with what will you recognize what Short URL represents. It is only arbitrary.
It contains a button that can fetch your Short URLs from a database into the table on the same page.
This project contains services:
- Automatic generation of backend resources, like database, collection and attributes once you visit
/
page in your browser. -
- To manually create backend resources, refer to these 2 files:
- Preview of generator form and your generated urls
- Generation of short url record
- Fork this repository
- Clone it locally
- Change project ID inisde appwrite.json file to your project ID.
- While in root folder, run appwrite cli command
appwrite deploy function
and follow steps to deploy it -
- If you don't have appwrite cli installed, check this link and install it on your device
- Once function is deployed, set environment variables to it:
-
- DOMAIN
-
- PROJECT_API_KEY
PROJECT-API-KEY is your api key from a project.
DOMAIN is your custom domain you want your function to run on. If you do not have custom domain registered and set, set your appwrite-gived domain for that function.
For example:
DOMAIN=624fbdf32f3aa04c42.appwrite.global
PROJECT_API_KEY=YOU API KEYWITH ALL PERMISSIONS
This project is developed with:
- Typescript
- appwrite-node
- HTML, CSS and JS for template
Refer to Package JSON file
- Locally, go to
functions/url-shortener
path. - Run
npm install
command - Start coding
NOTE: Make code adjustments only inside dev
folder. Code inside dev
folder will be built into src
folder.
- While inside
functions/url-shortener
path, runnom run build
command after you made your desired code changes - Go back to the root folder and run
appwrite deploy function
command. Follow the steps to deploy your function. - If needed, refer back to Manual Setup section
/
- Shows a static generator template and generated backend resources in the background if they do not exist./generate-short-url
:-
- Generates Short URL record
-
- Allows POST method only
-
- Must have
'Content-Type': 'application/json'
header
- Must have
-
- Allowed payload example:
JSON.stringify({
alias: ALIAS VALUE,
url: URL VALUE
})
-
/my-short-urls
- Gets your short url records -
- It will return 100 at the time. if you have more than 100 records, you need to update code to show more.
-
- Allows only POST method
-
- Must have
'Content-Type': 'application/json'
header
- Must have
-
/delete-record
: -
- Deletes Short URL record
-
- Allows POST method only
-
- Must have
'Content-Type': 'application/json'
header
- Must have
-
- Allowed payload example:
JSON.stringify({
id: Document ID from item
})
Refer to the template to see how it is used in the simple frontend.