next.config.js
file to use the Scale HTTP Adapter Webpack Loader:
--language
flag when creating a new Scale Function.scale.go
file that gets generated. The Scale Function is a simple HTTP handler that returns a Hello World
message:
hello-latest.scale
file in the current directory. Because of the way Next.js
deploys Edge Functions, we also need to export a raw version of the Scale Function. To do this, we can use the
--raw
flag with the previous export command:
hello-latest.wasm
file in the current directory. Now we have everything we need to import
the Scale Function into our Next.js App.
import
statement:
export const config = { runtime: 'edge' };
line to your API route. This tells Vercel to deploy
the API route as an Edge Function, which is required for WebAssembly modules to work.
You’ll also need to add the // @ts-ignore
comments to the import
statements to tell TypeScript to ignore the
.scale
and .wasm
file imports since webpack will handle them at build time.
?module
query parameter is required when importing a raw Scale Function (WebAssembly Module) into a Next.js App. This tells
Vercel to treat the file as a WebAssembly module and compile it to WebAssembly before deploying it. Vercel explicitly
disables compiling WebAssembly modules at runtime, which is why we need to import the raw .wasm
module at build time.Next.js App on http://localhost:3000