Skip to content

Commit

Permalink
Copy Template Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Dec 31, 2022
0 parents commit a176bb1
Show file tree
Hide file tree
Showing 35 changed files with 9,570 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
allow:
- dependency-name: '@edgio/*'
open-pull-requests-limit: 10
19 changes: 19 additions & 0 deletions .github/workflows/layer0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Deploy to Edgio

on:
workflow_dispatch:
push:

jobs:
deploy-to-layer0:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 14
registry-url: https://npm-proxy.fury.io/moovweb/
- run: npm ci
- run: npm run edgio:deploy -- --token=$LAYER0_DEPLOY_TOKEN
env:
LAYER0_DEPLOY_TOKEN: ${{secrets.LAYER0_DEPLOY_TOKEN}}
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# build output
/dist
/.layer0
/.edgio

# dependencies
/node_modules

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store

# vs-code specific files
/.vscode

sw/bundled-service-worker.js
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Expose Astro dependencies for `pnpm` users
shamefully-hoist=true
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.layer0
/.vscode
/dist
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Deploy Astro SSR example to Edgio

A demo deployment of Astro SSR app to Edgio.

## Demo

https://layer0-docs-layer0-astro-ssr-example-default.layer0-limelight.link

## Try It Now

[![Deploy with Edgio](https://docs.edg.io/button.svg)](https://app.layer0.co/deploy?repo=https://github.com/edgio-docs/edgio-astro-ssr-example)

## Getting Started

### Clone This Repo

Use `git clone https://github.com/edgio-docs/edgio-astro-ssr-example.git` to get the files within this repository onto your local machine.

### Install dependencies

On the command line, in the project root directory, run the following command:

```bash
npm install
```

### Run the Astro app locally on Edgio

Run the Astro app with the command:

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

Load the site: http://127.0.0.1:3000

### Testing production build locally with Edgio

You can do a production build of your app and test it locally using:

```bash
npm run edgio:build && npm run edgio:production
```

Setting --production runs your app exactly as it will be uploaded to the Edgio cloud using serverless-offline.

## Deploying to Edgio

Deploying requires an account on Edgio. [Sign up here for free](https://app.layer0.co/signup). Once you have an account, you can deploy to Edgio by running the following in the root folder of your project:

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

See [deploying](https://docs.edg.io/guides/deploying) for more information.
14 changes: 14 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import react from '@astrojs/react'
import tailwind from '@astrojs/tailwind'
import { defineConfig } from 'astro/config'

import node from '@astrojs/node'

// https://astro.build/config
export default defineConfig({
integrations: [react(), tailwind()],
output: 'server',
adapter: node({
mode: 'standalone',
}),
})
15 changes: 15 additions & 0 deletions buildServiceWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const esbuild = require('esbuild')

const appDir = process.cwd()

esbuild.buildSync({
entryPoints: [`${appDir}/sw/service-worker.js`],
outfile: `${appDir}/sw/bundled-service-worker.js`,
minify: true,
bundle: true,
define: {
'process.env.NODE_ENV': '"production"',
'process.env.EDGIO_PREFETCH_HEADER_VALUE': '"1"',
'process.env.EDGIO_PREFETCH_CACHE_NAME': '"prefetch"',
},
})
66 changes: 66 additions & 0 deletions cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export const PAGE_CACHE_HANDLER = ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 60,
},
})
}

export const API_CACHE_HANDLER = ({ cache, proxy }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60,
// Cache responses even if they contain cache-control: private header
// https://docs.edg.io/guides/caching#private
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
forcePrivateCaching: true,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
proxy('api', { path: ':path*' })
}

export const IMAGE_CACHE_HANDLER = ({ cache, proxy }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60,
// Cache responses even if they contain cache-control: private header
// https://docs.edg.io/guides/caching#private
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
forcePrivateCaching: true,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
proxy('image', { path: '/' })
}

export const ASSET_CACHE_HANDLER = ({ removeUpstreamResponseHeader, cache }) => {
// Remove the cache-control header coming in from the Next.js app,
// and remove the set-cookie header coming in from the Next.js app,
// this is to ensure that the response is cacheable
removeUpstreamResponseHeader('set-cookie')
removeUpstreamResponseHeader('cache-control')
// Set the caching values
cache({
edge: {
// Save the response(s) [whether stale or updated] in the edge POP for a year
maxAgeSeconds: 60 * 60 * 24 * 365,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
}
23 changes: 23 additions & 0 deletions edgio.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
connector: '@edgio/astro',
astro: {
appPath: './dist/server/entry.mjs',
},
backends: {
// Define a domain or IP address to proxy as a backend
// More on: https://docs.edg.io/guides/edgio_config#backends
api: {
domainOrIp: 'layer0-docs-layer0-ecommmerce-api-example-default.layer0-limelight.link',
hostHeader: 'layer0-docs-layer0-ecommmerce-api-example-default.layer0-limelight.link',
// Disable backend SSL certificate security check, read more on:
// https://docs.edg.io/guides/edgio_config#:~:text=browser%20is%20used.-,disableCheckCert,-Boolean
disableCheckCert: true,
},
// More on: https://docs.edg.io/guides/image_optimization
image: {
domainOrIp: 'opt.moovweb.net',
hostHeader: 'opt.moovweb.net',
disableCheckCert: true,
},
},
}
Loading

0 comments on commit a176bb1

Please sign in to comment.