Build Applications Quickly on the EDJX Platform (EDJURL Tutorial)
Using EDJX Platform components, you can build and deploy applications quickly and scale them globally with low latency.
EDJURL is an example application that is built and deployed using EDJX Platform. It shortens long URLs into more manageable and usable URLs.
EDJX Platform Components Used
To build this application, the following EDJX Platform components are used:
-
EDJX Serverless Functions executes code in the EDJURL application. The two serverless functions used are:
-
EDJX Storage stores the HTML content and images that form the user interface of the EDJURL application.
-
EDJX Domains routes the request to the
edjurl.com
domain. Request routing rules are used to divert traffic fromedjurl.com
to the appropriate EDJX Serverless Functions. -
EdjNet distributes the assets to make the EDJURL application instantly available and scalable globally.
For example, to shorten the https://example.org
URL, it is passed to the shorten
function. The function assigns a key and stores it in the KV Store. To fetch the original URL, the key value is passed to the fetch
function.
Steps to Build the Application
Follow the steps given below to quickly build and deploy the EDJURL application:
Build and Deploy shorten
Function (Rust)
Use the Rust code sample at GitHub to build and deploy the shorten
function.
To build the shorten
function:
-
Meet the prerequisites.
-
Open a terminal instance on your system.
-
Navigate to the
edjurl/rust_url_shorten
folder, which contains theshorten
function. -
Run the following command to compile:
cargo build --release --target=wasm32-unknown-unknown
This generates a WASM file, for example
urlshorten.wasm
, which you can deploy to EDJX.
To deploy the shorten
function:
-
Log in to EDJX Console.
-
Select an organization.
-
Create an application named EdjURL.
-
Create a function named
shorten
. -
Select the compiled WASM file.
-
Language: Rust
-
Function Name: shorten
-
File: urlshorten.wasm (WASM file generated during the Build step)
-
-
Grant the KV full access permission.
To run the shorten
function:
-
Copy and paste the
shorten
function URL in a Web browser. -
Append
?url=edjx.io
and get a short string.
Build and Deploy fetch
Function (C++)
Use the C++ code sample at GitHub to build and deploy the fetch
function.
To build the fetch
function:
-
Meet the prerequisites.
-
Open a terminal instance on your system.
-
Navigate to the
edjurl/cpp_url_fetch
folder, which contains thefetch
function. -
Run the following command to compile:
make all
This generates a WASM file, for example
urlfetch.wasm
, which you can deploy to EDJX.
To deploy the fetch
function:
-
Log in to EDJX Console.
-
Select the organization where the EDJURL application resides.
-
Navigate to the EdjURL application.
-
Create a function named
fetch
. -
Select the compiled WASM file.
-
Language: C++
-
Function Name: fetch
-
File: urlfetch.wasm (WASM file generated during the Build step)
-
-
Grant the KV read permission.
To run the fetch
function:
-
Copy the
fetch
function URL and paste it into a Web browser. -
Append the short string you generated in the
shorten
function as?s=SHORTSTRING
.The short string redirects to the original URL,
https://edjx.io
.
Build and Deploy the HTML Page
To build the HTML page, navigate to the scripts.js file and set APP_URL
variable to the shorten
function.
The FETCH_PREFIX is a URL to the serverless function that retrieves a shortened URL.
|
To deploy the HTML page:
-
Log in to EDJX Console.
-
Select an organization.
-
Create a bucket named
EdjURL
and make it public. -
Upload the website files to the bucket, one at a time.
-
Set the Content-Disposition header to inline for the
index.html
file to display the HTML file as a web page.
To run the HTML page:
Copy the URL of the index.html
page and paste it into a Web browser.
You can now shorten URLs.
Set up a Domain for the Application (Optional)
Optionally you can set up a domain to host the application. For example, if you want to use example.org
, then ensure that you have a registered example.org
domain and the Domain DNS records point to EDJX. This tutorial uses the edjurl.com
domain.
To set up a domain:
-
Log in to EDJX Console.
-
Select an organization.
-
Navigate to Domains.
-
Create a domain named edjurl.com.
-
Add a DNS A record. The IP Address can be an arbitrary value.
-
Type: A
-
Name: @
-
Target: 144.126.248.201
-
TTL: 1800
-
Proxy: ON
-
-
Add Rewrite Rule: edjurl.com → display the HTML page
-
Name: Homepage
-
Match Type: Exact Match
-
Match Value: edjurl.com
-
Action: Redirect
-
Routing Destination:
https://[BucketID].storage.edjx.net/blobs/index.html
This is a URL to the index.html
file in the bucket.
-
-
Add Rewrite Rule: edjurl.com/?s= → call URL fetch
-
Name: Fetch
-
Match Type: Pattern Match
-
Match Value: edjurl.com/?s=*
-
Action: Redirect
-
Routing Destination:
https://[AppID].fn.edjx.net/fetch?{query}
-
It is important to place the rules in the correct order. Place the Fetch rule before the Home rule. |
To enable HTTPS for EDJURL, add a TLS certificate. |