Skip to content

Commit 530088c

Browse files
feat: add support for WebAssembly in edge runtime (#1676)
* feat: add wasm support * chore: snapidoo * chore: log * chore: log fetch wrapper * fix: allow acess to edge-chunks * chore: make example more dynamic * chore: add image debug, remove logs * chore: remove debug * fix: inlline assets * chore: nicer example * chore: error handling * chore: remove log and format * chore: add e2e test * chore: fix test * chore: re-enable dev check in edge function * chore: change from review * chore: update snapshots * fix: correct content-length in middleware Co-authored-by: Nick Taylor <[email protected]>
1 parent 05a9d58 commit 530088c

File tree

10 files changed

+387
-50
lines changed

10 files changed

+387
-50
lines changed
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe('WebAssembly support', () => {
2+
it('generates an API route with wasm chunks', () => {
3+
cy.request('/api/og?username=netlify').then((response) => {
4+
// Failure state is zero-length body
5+
expect(response.body).to.have.length.above(10000)
6+
})
7+
})
8+
})

demos/default/next.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ module.exports = {
7575
remotePatterns: [
7676
{
7777
hostname: '*.imgur.com',
78-
}
79-
]
78+
},
79+
],
8080
},
8181
// https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options
8282
sassOptions: {
8383
includePaths: [path.join(__dirname, 'styles-sass-test')],
8484
},
8585
experimental: {
8686
optimizeCss: false,
87-
}
87+
},
8888
}

demos/default/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"@reach/dialog": "^0.16.2",
2222
"@reach/visually-hidden": "^0.16.0",
23+
"@vercel/og": "^0.0.15",
2324
"next": "^12.3.0",
2425
"react": "^18.0.0",
2526
"react-dom": "^18.0.0"

demos/default/pages/api/og.tsx

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { ImageResponse } from '@vercel/og'
2+
import { NextRequest } from 'next/server'
3+
4+
export const config = {
5+
runtime: 'experimental-edge',
6+
}
7+
8+
export default async function handler(req: NextRequest) {
9+
const { searchParams } = req.nextUrl
10+
const username = searchParams.get('username')
11+
12+
return new ImageResponse(
13+
(
14+
<div
15+
style={{
16+
display: 'flex',
17+
fontSize: 60,
18+
color: 'black',
19+
background: '#f6f6f6',
20+
width: '100%',
21+
height: '100%',
22+
paddingTop: 50,
23+
flexDirection: 'column',
24+
justifyContent: 'center',
25+
alignItems: 'center',
26+
}}
27+
>
28+
<img
29+
width="256"
30+
height="256"
31+
src={`https://github.com/${username || 'netlify'}.png`}
32+
style={{
33+
borderRadius: 128,
34+
}}
35+
/>
36+
{username ? <p>github.com/{username}</p> : <p>Visit with &quot;?username=netlify&quot;</p>}
37+
</div>
38+
),
39+
{
40+
width: 1200,
41+
height: 630,
42+
headers: {
43+
// By default this has an immutable cache, but this is for testing
44+
'Cache-Control': 'public, max-age=0, must-revalidate',
45+
},
46+
},
47+
)
48+
}

0 commit comments

Comments
 (0)