Skip to content

Commit

Permalink
Add template repos
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlee85 committed May 9, 2024
1 parent 2d222c1 commit bb3778b
Show file tree
Hide file tree
Showing 9 changed files with 10,901 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-edge-function-template/.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: 18
- 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-edge-function-template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Edgio generated build directory
/.edgio

/node_modules
27 changes: 27 additions & 0 deletions examples/v7-edge-function-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This is base Edgio template project with edge function support. You may create a new property using this template from the [Edgio Console](https://app.edg.io).

## Getting Started

### Install Packages

```bash
npm install
```

### Local Development Server

```bash
npm run edgio:dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Deploy on Edgio

Deploy this project on Edgio with the following command:

```bash
npm run edgio:deploy
```

Check out our [Edge Functions documentation](https://docs.edg.io/applications/v7/edge_functions) for more details.
29 changes: 29 additions & 0 deletions examples/v7-edge-function-template/edge-functions/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 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) {
console.log(request.url)
const resp = await fetch('https://test-origin.edgio.net', {
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
}
90 changes: 90 additions & 0 deletions examples/v7-edge-function-template/edgio.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// 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-edge-function-template-example",

// The name of the organization in Edgio to which this app should be deployed.
// organization: 'my-organization-name',

// Overrides the default path to the routes file. The path should be relative to the root of your app.
// routes: 'routes.js',

// When set to true or omitted entirely, Edgio includes the deployment number in the cache key,
// effectively purging the cache each time you deploy.
purgeCacheOnDeploy: true,
// purgeCacheOnDeploy: false,

origins: [
{
// The name of the backend origin
name: "origin",

// Use the following to override the host header sent from the browser when connecting to the origin
override_host_header: "test-origin.edgio.net",

// The list of origin hosts to which to connect
hosts: [
{
// The domain name or IP address of the origin server
location: "test-origin.edgio.net",
},
],

tls_verify: {
use_sni: true,
sni_hint_and_strict_san_check: "test-origin.edgio.net",
},

// Uncomment the following to configure a shield
// shields: { us_east: 'DCD' },
},
],

// Uncomment the following to specify environment specific configs
// environments: {
// production: {
// hostnames: [{ hostname: 'www.mysite.com' }],
// },
// staging: {
// hostnames: [{ hostname: 'staging.mysite.com' }],
// origins: [
// {
// name: 'origin',
// hosts: [{ location: 'staging-origin.mysite.com' }],
// override_host_header: 'staging-origin.mysite.com',
// tls_verify: {
// use_sni: true,
// sni_hint_and_strict_san_check: 'staging-origin.mysite.com',
// },
// shields: { us_east: 'DCD' },
// },
// ],
// },
// },

// Options for hosting serverless functions on Edgio
// serverless: {
// // Set to true to include all packages listed in the dependencies property of package.json when deploying to Edgio.
// // This option generally isn't needed as Edgio automatically includes all modules imported by your code in the bundle that
// // is uploaded during deployment
// includeNodeModules: true,
//
// // Include additional paths that are dynamically loaded by your app at runtime here when building the serverless bundle.
// include: ['views/**/*'],
// },

// The maximum number of URLs that will be concurrently prerendered during deployment when static prerendering is enabled.
// Defaults to 200, which is the maximum allowed value.
// prerenderConcurrency: 200,

// A list of glob patterns identifying which source files should be uploaded when running edgio deploy --includeSources.
// This option is primarily used to share source code with Edgio support personnel for the purpose of debugging. If omitted,
// edgio deploy --includeSources will result in all files which are not gitignored being uploaded to Edgio.
//
// sources : [
// '**/*', // include all files
// '!(**/secrets/**/*)', // except everything in the secrets directory
// ],
};
Loading

0 comments on commit bb3778b

Please sign in to comment.