Skip to content

Commit

Permalink
Base project for image opt
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlee85 committed Oct 24, 2023
1 parent 84235b4 commit dba2ad1
Show file tree
Hide file tree
Showing 8 changed files with 25,811 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**NOTICE TO CONTRIBUTORS**

This repository is not actively monitored and any pull requests made to this repository will be closed/ignored.

Please submit the pull request to [edgio-docs/edgio-examples](https://github.com/edgio-docs/edgio-examples) instead.
18 changes: 18 additions & 0 deletions examples/v7-image-optimization/.github/workflows/edgio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy to Edgio

on:
workflow_dispatch:
push:

jobs:
deploy-to-edgio:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: if [ -f yarn.lock ]; then yarn install; else npm ci; fi
- run: if [ -f yarn.lock ]; then yarn edgio:deploy -- --token=$EDGIO_DEPLOY_TOKEN; else npm run edgio:deploy -- --token=$EDGIO_DEPLOY_TOKEN; fi
env:
EDGIO_DEPLOY_TOKEN: ${{secrets.EDGIO_DEPLOY_TOKEN}}
4 changes: 4 additions & 0 deletions examples/v7-image-optimization/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Edgio generated build directory
/.edgio

/node_modules
28 changes: 28 additions & 0 deletions examples/v7-image-optimization/edge-functions/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* An example edge function which forwards the request to the origin.
* See routes.js for how this function is configured to run for requests to "/".
*/
export async function handleHttpRequest(request) {
const resp = await fetch(`https://test-origin.edgio.net${request.path}`, {
edgio: {
origin: 'origin', // this corresponds to the name of the origin in edgio.config.js
},
})

// handle the response as needed
// For example, to inject some html into the body:
const html = await resp.text()
const newHtml = html.replace('</body>', '<marquee>Added by edge functions!</marquee></body>')

// To send the response to the client with the new HTML but the same headers as the origin response:
return new Response(newHtml, {
...resp,
headers: {
...resp.headers,
'x-edge-function': 'main.js',
},
})

// Or you can just return the original response to the client
// return resp
}
38 changes: 38 additions & 0 deletions examples/v7-image-optimization/edgio.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file was automatically added by edgio init.
// You should commit this file to source control.
// Learn more about this file at https://docs.edg.io/guides/edgio_config
module.exports = {
// The name of the site in Edgio to which this app should be deployed.
name: 'edgio-v7-image-optimization-example',

origins: [
{
name: 'origin',
override_host_header: 'en.wikipedia.org',
hosts: [
{
location: 'en.wikipedia.org',
},
],
tls_verify: {
use_sni: true,
allow_self_signed_certs: true,
sni_hint_and_strict_san_check: 'en.wikipedia.org',
},
},
{
name: 'upload',
override_host_header: 'upload.wikimedia.org',
hosts: [
{
location: 'upload.wikimedia.org',
},
],
tls_verify: {
use_sni: true,
allow_self_signed_certs: true,
sni_hint_and_strict_san_check: 'upload.wikimedia.org',
},
},
],
};
Loading

0 comments on commit dba2ad1

Please sign in to comment.