Skip to content

Commit a176bb1

Browse files
author
root
committed
Copy Template Repo
0 parents  commit a176bb1

35 files changed

Lines changed: 9570 additions & 0 deletions

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'npm'
4+
directory: '/'
5+
schedule:
6+
interval: 'daily'
7+
allow:
8+
- dependency-name: '@edgio/*'
9+
open-pull-requests-limit: 10

.github/workflows/layer0.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Deploy to Edgio
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
7+
jobs:
8+
deploy-to-layer0:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 14
15+
registry-url: https://npm-proxy.fury.io/moovweb/
16+
- run: npm ci
17+
- run: npm run edgio:deploy -- --token=$LAYER0_DEPLOY_TOKEN
18+
env:
19+
LAYER0_DEPLOY_TOKEN: ${{secrets.LAYER0_DEPLOY_TOKEN}}

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# build output
2+
/dist
3+
/.layer0
4+
/.edgio
5+
6+
# dependencies
7+
/node_modules
8+
9+
# logs
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
pnpm-debug.log*
14+
15+
16+
# environment variables
17+
.env
18+
.env.production
19+
20+
# macOS-specific files
21+
.DS_Store
22+
23+
# vs-code specific files
24+
/.vscode
25+
26+
sw/bundled-service-worker.js

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Expose Astro dependencies for `pnpm` users
2+
shamefully-hoist=true

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.layer0
2+
/.vscode
3+
/dist

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Deploy Astro SSR example to Edgio
2+
3+
A demo deployment of Astro SSR app to Edgio.
4+
5+
## Demo
6+
7+
https://layer0-docs-layer0-astro-ssr-example-default.layer0-limelight.link
8+
9+
## Try It Now
10+
11+
[![Deploy with Edgio](https://docs.edg.io/button.svg)](https://app.layer0.co/deploy?repo=https://github.com/edgio-docs/edgio-astro-ssr-example)
12+
13+
## Getting Started
14+
15+
### Clone This Repo
16+
17+
Use `git clone https://github.com/edgio-docs/edgio-astro-ssr-example.git` to get the files within this repository onto your local machine.
18+
19+
### Install dependencies
20+
21+
On the command line, in the project root directory, run the following command:
22+
23+
```bash
24+
npm install
25+
```
26+
27+
### Run the Astro app locally on Edgio
28+
29+
Run the Astro app with the command:
30+
31+
```bash
32+
npm run edgio:dev
33+
```
34+
35+
Load the site: http://127.0.0.1:3000
36+
37+
### Testing production build locally with Edgio
38+
39+
You can do a production build of your app and test it locally using:
40+
41+
```bash
42+
npm run edgio:build && npm run edgio:production
43+
```
44+
45+
Setting --production runs your app exactly as it will be uploaded to the Edgio cloud using serverless-offline.
46+
47+
## Deploying to Edgio
48+
49+
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:
50+
51+
```bash
52+
npm run edgio:deploy
53+
```
54+
55+
See [deploying](https://docs.edg.io/guides/deploying) for more information.

astro.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import react from '@astrojs/react'
2+
import tailwind from '@astrojs/tailwind'
3+
import { defineConfig } from 'astro/config'
4+
5+
import node from '@astrojs/node'
6+
7+
// https://astro.build/config
8+
export default defineConfig({
9+
integrations: [react(), tailwind()],
10+
output: 'server',
11+
adapter: node({
12+
mode: 'standalone',
13+
}),
14+
})

buildServiceWorker.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const esbuild = require('esbuild')
2+
3+
const appDir = process.cwd()
4+
5+
esbuild.buildSync({
6+
entryPoints: [`${appDir}/sw/service-worker.js`],
7+
outfile: `${appDir}/sw/bundled-service-worker.js`,
8+
minify: true,
9+
bundle: true,
10+
define: {
11+
'process.env.NODE_ENV': '"production"',
12+
'process.env.EDGIO_PREFETCH_HEADER_VALUE': '"1"',
13+
'process.env.EDGIO_PREFETCH_CACHE_NAME': '"prefetch"',
14+
},
15+
})

cache.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
export const PAGE_CACHE_HANDLER = ({ cache }) => {
2+
cache({
3+
edge: {
4+
maxAgeSeconds: 60,
5+
},
6+
})
7+
}
8+
9+
export const API_CACHE_HANDLER = ({ cache, proxy }) => {
10+
cache({
11+
edge: {
12+
maxAgeSeconds: 60 * 60,
13+
// Cache responses even if they contain cache-control: private header
14+
// https://docs.edg.io/guides/caching#private
15+
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
16+
forcePrivateCaching: true,
17+
},
18+
browser: {
19+
// Don't save the response in the browser
20+
maxAgeSeconds: 0,
21+
// Save the response in the browser via Edgio service worker
22+
serviceWorkerSeconds: 60 * 60 * 24,
23+
},
24+
})
25+
proxy('api', { path: ':path*' })
26+
}
27+
28+
export const IMAGE_CACHE_HANDLER = ({ cache, proxy }) => {
29+
cache({
30+
edge: {
31+
maxAgeSeconds: 60 * 60,
32+
// Cache responses even if they contain cache-control: private header
33+
// https://docs.edg.io/guides/caching#private
34+
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
35+
forcePrivateCaching: true,
36+
},
37+
browser: {
38+
// Don't save the response in the browser
39+
maxAgeSeconds: 0,
40+
// Save the response in the browser via Edgio service worker
41+
serviceWorkerSeconds: 60 * 60 * 24,
42+
},
43+
})
44+
proxy('image', { path: '/' })
45+
}
46+
47+
export const ASSET_CACHE_HANDLER = ({ removeUpstreamResponseHeader, cache }) => {
48+
// Remove the cache-control header coming in from the Next.js app,
49+
// and remove the set-cookie header coming in from the Next.js app,
50+
// this is to ensure that the response is cacheable
51+
removeUpstreamResponseHeader('set-cookie')
52+
removeUpstreamResponseHeader('cache-control')
53+
// Set the caching values
54+
cache({
55+
edge: {
56+
// Save the response(s) [whether stale or updated] in the edge POP for a year
57+
maxAgeSeconds: 60 * 60 * 24 * 365,
58+
},
59+
browser: {
60+
// Don't save the response in the browser
61+
maxAgeSeconds: 0,
62+
// Save the response in the browser via Edgio service worker
63+
serviceWorkerSeconds: 60 * 60 * 24,
64+
},
65+
})
66+
}

edgio.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
connector: '@edgio/astro',
3+
astro: {
4+
appPath: './dist/server/entry.mjs',
5+
},
6+
backends: {
7+
// Define a domain or IP address to proxy as a backend
8+
// More on: https://docs.edg.io/guides/edgio_config#backends
9+
api: {
10+
domainOrIp: 'layer0-docs-layer0-ecommmerce-api-example-default.layer0-limelight.link',
11+
hostHeader: 'layer0-docs-layer0-ecommmerce-api-example-default.layer0-limelight.link',
12+
// Disable backend SSL certificate security check, read more on:
13+
// https://docs.edg.io/guides/edgio_config#:~:text=browser%20is%20used.-,disableCheckCert,-Boolean
14+
disableCheckCert: true,
15+
},
16+
// More on: https://docs.edg.io/guides/image_optimization
17+
image: {
18+
domainOrIp: 'opt.moovweb.net',
19+
hostHeader: 'opt.moovweb.net',
20+
disableCheckCert: true,
21+
},
22+
},
23+
}

0 commit comments

Comments
 (0)