edgestorejs/edgestore

Getting Server Error 500

Closed this issue · 3 comments

Hello,

I was trying to use edgestore in my NextJS app (NextJs -> 14.0.1). I followed the steps mentioned in the documentation and I noticed that I am getting this error when the app starts:

Request URL: http://localhost:3001/api/edgestore/init
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: [::1]:3001
Referrer Policy: strict-origin-when-cross-origin

And I can see the response message is showing Missing path param

When I try to ignore the error and proceed to upload the image anyway. I get the same error but of course the API path will be different since it will be now trying to upload the image.

I have configured my .env file correctly with the key I got from the project.

Here is the route.ts code:

import { currentUser, redirectToSignIn } from "@clerk/nextjs"
import { initEdgeStore } from "@edgestore/server"
import {
  CreateContextOptions,
  createEdgeStoreNextHandler,
} from "@edgestore/server/adapters/next/app"
import { z } from "zod"

type Context = {
  userId: string | undefined
}

async function createContext({ req }: CreateContextOptions): Promise<Context> {
  const user = await currentUser()
  return {
    userId: user?.id,
  }
}

const es = initEdgeStore.context<Context>().create()

const edgeStoreRouter = es.router({
  publicImages: es
    .imageBucket({
      maxSize: 1024 * 1024 * 1, //1MB
      accept: ["image/jpeg", "image/png"],
    })
    .input(
      z.object({
        type: z.enum(["post", "profile", "market"]),
      })
    )
    .path(({ input }) => [{ type: input.type }, {}])
    .accessControl({
      userId: { not: undefined },
    }),
})
const handler = createEdgeStoreNextHandler({
  router: edgeStoreRouter,
  createContext,
})
export { handler as GET, handler as POST }
export type EdgeStoreRouter = typeof edgeStoreRouter

Here is the provider code:

"use client"

import { createEdgeStoreProvider } from "@edgestore/react"

import { type EdgeStoreRouter } from "@/app/api/edgestore/[...edgestore]/route"

const { EdgeStoreProvider, useEdgeStore } =
  createEdgeStoreProvider<EdgeStoreRouter>()

export { EdgeStoreProvider, useEdgeStore }

I am stuck here and I am not sure why I keep getting the 500 error. I can't even see this error in my VSCode console

Any idea how to fix this?

Hi @yousihy!
I think deleting the {} in the path config should fix your problem.
.path(({ input }) => [{ type: input.type }, {}]) -> .path(({ input }) => [{ type: input.type }])

I'll try to improve the type definition so that typescript shows this error.

Hi @yousihy! I think deleting the {} in the path config should fix your problem. .path(({ input }) => [{ type: input.type }, {}]) -> .path(({ input }) => [{ type: input.type }])

I'll try to improve the type definition so that typescript shows this error.

Thanks! that solved the issue. I am not sure how I missed that.

The issue is resolved by removing the extra {} as @perfectbase suggested