Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Error] TypeError: Cannot read properties of undefined (reading 'options') #36

Open
phucledien opened this issue Feb 6, 2025 · 5 comments

Comments

@phucledien
Copy link

Step to reproduce

  1. Init project
  2. Setup .env with db_url
  3. run npm run db:push
  4. run npx wrangler dev
  5. Access the sample api at path localhost:8080/api/post/recent

Images

Image

@ajiohjesse
Copy link
Contributor

Are there any errors in the dev tools?

@Shivam-002
Copy link

Can you try this in server/index.ts

const appCors = cors({
  allowHeaders: ["x-is-superjson", "Content-Type"],
  exposeHeaders: ["x-is-superjson"],
  allowMethods: ["GET", "POST", "PUT", "DELETE","OPTIONS"],
  origin: "http://localhost:3000",
  credentials: true,
});

/**
 * This is your base API.
 * Here, you can handle errors, not-found responses, cors and more.
 *
 * @see https://jstack.app/docs/backend/app-router
 */
const api = j
  .router()
  .basePath("/api")
  .use(appCors)
  .onError(j.defaults.errorHandler);

@joschan21
Copy link
Collaborator

the CORS above probably fixes the issue, let us know if it worked. Thanks @Shivam-002 for helping. Might be worth adding to the default CORS middleware if multiple people face this issue, what was the use case that surfaced this problem?

@phucledien
Copy link
Author

still got the error 🤔 as the err stack trace showing I think the issue related to init postgres.

@Shivam-002
Copy link

Can you please share your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants