You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey saw the guide over at Zuplo and love what you have built here. I know their guide showed the Pages Router API route and I see your update to support the App Router... But I want to use the Pages API Route with Edge runtime. Is this possible?
export const config = { runtime: "edge" }
This is the error I'm getting -
⨯ Error: The edge runtime does not support Node.js 'path' module.
Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime
at [project]/node_modules/@subzerocloud/nodejs/index.js [edge-api] (ecmascript) (.next/server/edge/chunks/_d81405._.js:10225:168)
at [project]/src/pages/api/[...query].ts [edge-api] (ecmascript) (src/pages/api/[...query].ts:7:0)
5 | // The code provided in next.config.ts should work once those issues are fixed.
6 |> 7 | import Subzero, {
8 | SubzeroError,
9 | getIntrospectionQuery,
10 | Env as QueryEnv
GET /api/user?select=* 500 in 89ms
/pages/api/[...query].ts
// Due to various issues with Vercel bundling the wasm file when using the app// directory (ex. https://github.com/orgs/vercel/discussions/1278), I was// unfortunately not able to get this working. I even tried a standalone// but hit https://github.com/vercel/next.js/issues/50072// The code provided in next.config.ts should work once those issues are fixed.importSubzero,{SubzeroError,getIntrospectionQuery,EnvasQueryEnv}from"@subzerocloud/nodejs"import{neon,NeonQueryFunction}from"@neondatabase/serverless"consturlPrefix="/api"constpublicSchema="public"constdbType="postgresql"exportconstdynamic="force-dynamic"// static by default, unless reading the requestletsubzero: Subzeroconstrole="anonymous"asyncfunctioninitSubzero(sql: NeonQueryFunction<false,false>){const{ query, parameters }=getIntrospectionQuery(dbType,publicSchema// the schema name that is exposed to the HTTP api (ex: public, api))constdata=awaitsql(query,parameters)// the result of the introspection query is a json string representation of the database schema/structure// this schema object is used to generate the queries and check the permissions// to make the function startup faster, one can cache the schema objectconstschema=JSON.parse(data[0].json_schema)subzero=newSubzero(dbType,schema)}consthandler=async(request: Request)=>{constmethod=request.methodif(!process.env.DATABASE_URL){thrownewError("DATABASE_URL is not set")}if(!["GET","POST","PUT","DELETE","PATCH"].includes(method)){thrownewSubzeroError(`Method ${method} not allowed`,400)}constsql=neon(process.env.DATABASE_URL!)// initialize the subzero instance if it is not initialized yetif(!subzero){awaitinitSubzero(sql)}constqueryEnv: QueryEnv=[["role",role],["request.method",method],["request.headers",JSON.stringify(request.headers)],["request.jwt.claims",JSON.stringify({ role })],]const{ query, parameters }=awaitsubzero.fmtStatement(publicSchema,`${urlPrefix}/`,role,request,queryEnv)letresult: Record<string,unknown>[]try{result=awaitsql(query,parameters)}catch(e){console.error(`Error performing query ${query} with parameters ${parameters}`,e)throwe}constheaders={"content-type": "application/json",}returnnewResponse(JSON.stringify(result),{status: 200,
headers,})}exportdefaulthandlerexportconstconfig={runtime: "edge"}
The text was updated successfully, but these errors were encountered:
This polyfill for path should work, not sure what others might be needed to support Edge.
I'm working on a SWR Hook Generator project that will create useSWR hooks for React that are totally type safe and introspect the types from the database using Kysely codegen to pull down the types. The useSWR hooks will use the @supabase/postgrest-js client to interface with Subzero Postgrest, preferably running on Vercel Edge, and from there using Neon Serverless for optimal latency. And I'm planning to top all of that off with Better-Auth + JWT plugin for Neon RLS, and then running everything through Upstash rate limiting in middleware.ts. Magic Christmas Dreamland?
daveycodez
changed the title
NextJS Edge Runtime (Pages Router API
NextJS Edge Runtime (+ Vercel Edge Functions)
Dec 17, 2024
Hey saw the guide over at Zuplo and love what you have built here. I know their guide showed the Pages Router API route and I see your update to support the App Router... But I want to use the Pages API Route with Edge runtime. Is this possible?
export const config = { runtime: "edge" }
This is the error I'm getting -
/pages/api/[...query].ts
The text was updated successfully, but these errors were encountered: