This repository provides example code for implementing the most common use cases on Edge Functions. It features examples of how to add headers to a request, change response bodies before returning them to the client, create HTML pages from scratch to return as a response, manipulate video player manifests, and generate JSON from scratch.
To use this project, you must be an Edgio customer and signed up for the Edge Functions. The system requirements include Node.js v16 or higher, and a UNIX-like system (Linux or macOS). The project code is written in JavaScript.
- Ensure you meet the prerequisites.
- Clone the repository to your local machine.
- Run
npm installin the repository directory.
npm iAfter setting up the project, run npm run edgio dev to start a local development server to test the example functions.
npm run edgio devTo deploy the project to Edgio, use the command npm run edgio deploy. Note that deployment to Edgio requires you to be logged into Edgio CLI which can be done via npm run edgio login and following the instructions.
npm run edgio deployStart the React frontend by running npm run dev.
npm run devEdge Functions must be enabled for your team, which can be done by contacting your account manager at Edgio and signing up for the Edge Functions.
By default, for Edge Functions
- We only support JavaScript-based code
- Each request has a 60-second (wall time) timeout limit
- Each request is limited to 50ms of CPU time
- Each request is limited to 4MB of memory
- An Edgio Function can make fetch requests only to origins defined in your property configuration
file (
edgio.config.js).
Please refer to our documentation website on most up to date information about Edge Functions limitations. We're looking forward to feedback from our customers about these limitations and how we can improve the product.
If you have any queries or face issues with this project, please don't hesitate to contact the Edgio team.
Creative Commons Attribution 4.0 International Public License for the documentation.
MIT License for the code.
If you're on MacOS you can install the CLI with Homebrew:
brew install chiselstrike/tap/turso
turso auth signupturso db create my-db
turso db tokens create my-dbSet your token and URL variables in functions/edge-database-turso.js.
const TURSO_URL = ""
const AUTH_TOKEN = ""turso db shell my-dbcreate table users (id text, email text);
insert into users values ("001", "first@foo.com");
insert into users values ("002", "second@foo.com");
select * from users;
.quitSet HOST_HEADER environment variable with your Turso domain.
HOST_HEADER=""brew install planetscale/tap/pscale
# Check your `pscale` version
pscale version
# Authenticate with your PlanetScale account
pscale auth loginpscale database create edgio-mysql --region us-westpscale shell edgio-mysql mainCreate a new table called greeting_table with a single text column called Greeting.
CREATE TABLE greeting_table (
greeting text,
id int not null auto_increment,
primary key (id)
);Insert two rows into the table.
INSERT INTO greeting_table (greeting) VALUES ('Hello'), ('Goodbye');Return the list of available tables.
show tables;Return all the data in the greeting_table table.
SELECT * FROM greeting_table;+---------+----+
| greeting | id |
+---------+----+
| Hello | 1 |
| Goodbye | 2 |
+---------+----+
Promote branch to production:
pscale branch promote edgio-mysql mainCreate password:
pscale password create edgio-mysql main mypassmysql -h aws.connect.psdb.cloud \
-u USERNAME \
-pPASSWORD \
--ssl-mode=VERIFY_IDENTITY \
--ssl-ca=/etc/ssl/cert.pemSELECT * FROM greeting_table;