File tree Expand file tree Collapse file tree 6 files changed +73
-1
lines changed Expand file tree Collapse file tree 6 files changed +73
-1
lines changed Original file line number Diff line number Diff line change @@ -171,3 +171,25 @@ jobs:
171171 for ((i=0; i<retries; i++)); do
172172 bun test && break || echo "Test failed, retrying..."
173173 done
174+
175+ integration-nextjs :
176+ needs : [test, build]
177+ runs-on : ubuntu-latest
178+
179+ env :
180+ REPLICATE_API_TOKEN : ${{ secrets.REPLICATE_API_TOKEN }}
181+
182+ steps :
183+ - uses : actions/checkout@v4
184+ - uses : actions/download-artifact@v3
185+ with :
186+ name : package-tarball
187+ - name : Use Node.js
188+ uses : actions/setup-node@v4
189+ with :
190+ node-version : 20.x
191+ cache : " npm"
192+ - run : |
193+ npm --prefix integration/next install
194+ npm --prefix integration/next install "./${{ needs.build.outputs.tarball-name }}"
195+ npm --prefix integration/next run build
Original file line number Diff line number Diff line change 1+ package-lock = false
2+ audit = false
3+ fund = false
Original file line number Diff line number Diff line change 1+ // NOTE: This file currently doesn't do anything other than
2+ // validate that `next build` works as expected. We can
3+ // extend it in future to support actual middleware tests.
4+ import { NextRequest } from "next/server" ;
5+ import Replicate from "replicate" ;
6+
7+ // Limit the middleware to paths starting with `/api/`
8+ export const config = {
9+ matcher : "/api/:function*" ,
10+ } ;
11+
12+ const replicate = new Replicate ( ) ;
13+
14+ export function middleware ( request : NextRequest ) {
15+ const output = replicate . run ( "foo/bar" ) ;
16+ return Response . json ( { output } , 200 ) ;
17+ }
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " replicate-next" ,
3+ "version" : " 0.0.0" ,
4+ "private" : true ,
5+ "scripts" : {
6+ "dev" : " next" ,
7+ "build" : " rm -rf .next && next build" ,
8+ "start" : " next start"
9+ },
10+ "dependencies" : {
11+ "next" : " ^14.2.3" ,
12+ "replicate" : " ../../"
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ export default ( ) => (
2+ < main >
3+ < h1 > Welcome to Next.js</ h1 >
4+ </ main >
5+ )
Original file line number Diff line number Diff line change @@ -90,7 +90,18 @@ async function createHMACSHA256(secret, data) {
9090
9191 // In Node 18 the `crypto` global is behind a --no-experimental-global-webcrypto flag
9292 if ( typeof crypto === "undefined" && typeof require === "function" ) {
93- crypto = require ( "node:crypto" ) . webcrypto ;
93+ // NOTE: Webpack (primarily as it's used by Next.js) and perhaps some
94+ // other bundlers do not currently support the `node` protocol and will
95+ // error if it's found in the source. Other platforms like CloudFlare
96+ // will only support requires when using the node protocol.
97+ //
98+ // As this line is purely to support Node 18.x we make an indirect request
99+ // to the require function which fools Webpack...
100+ //
101+ // We may be able to remove this in future as it looks like Webpack is getting
102+ // support for requiring using the `node:` protocol.
103+ // See: https://github.com/webpack/webpack/issues/18277
104+ crypto = require . call ( null , "node:crypto" ) . webcrypto ;
94105 }
95106
96107 const key = await crypto . subtle . importKey (
You can’t perform that action at this time.
0 commit comments