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

got Invalid request body when using astro endpoint on vercel #6399

Closed
1 task
Kalo0m opened this issue Mar 1, 2023 · 8 comments
Closed
1 task

got Invalid request body when using astro endpoint on vercel #6399

Kalo0m opened this issue Mar 1, 2023 · 8 comments
Labels
pkg: vercel Related to Vercel adapter (scope)

Comments

@Kalo0m
Copy link

Kalo0m commented Mar 1, 2023

What version of astro are you using?

2.0.15

Are you using an SSR adapter? If so, which one?

Vercel - serverless

What package manager are you using?

pnpm's monorepo

What operating system are you using?

Windows

Describe the Bug

I created a post endpoint which parse the body to extract an email from.

export const post: APIRoute = async ({ request, url }) => {
  const body = await body.json()
  await prisma.user.create({
    data: {
      email: body.email,
    },
  });
  return {
    status: 200,
    headers: {
      'content-type': 'application/json',
    },
    body: JSON.stringify({ email }),
  };
};

and fetch it in a react client loaded component :

  const onSubmit = (email: string) => {
    fetch('/signin?email=${email}', {
      method: 'post',
      body: JSON.stringify({ email }),
    });
  };

It works perfectly locally but when deployed to vercel, when I call the endpoint I get Invalid request body before running the function. Is it a bug or do I misunderstand something ?

ps : here is my astro.config

import vercel from '@astrojs/vercel/serverless';

// https://astro.build/config
export default defineConfig({
  output: 'server',
  integrations: [react(), vercel()],
});

thanks for your help and your amazing work !

I've created a minimal reproduction which I've deployed to vercel and I got the same error (that's the link of the deployed project astro-vc4bqx.vercel.app). If you send a post request with a body to https://astro-vc4bqx.vercel.app/signin you will get the error

Link to Minimal Reproducible Example

https://stackblitz.com/edit/astro-vc4bqx?file=src/pages/signin.ts

Participation

  • I am willing to submit a pull request for this issue.
@w3bdesign
Copy link

w3bdesign commented Mar 2, 2023

@Kalo0m

I checked your code, and it looks like you are missing this line in the Astro config file:

adapter: vercel(),

However, this seems to be a bug with the Vercel adapter, it will likely be fixed in the next release. (0e378c3#diff-fcd4c8e46e5a2cfcf6a4685f019e9dab4250dabf3220351d3b5e3df12fdc3c35R104)

@Kalo0m
Copy link
Author

Kalo0m commented Mar 2, 2023

@w3bdesign Yes sorry, I fixed the config and still get the error. Will the next release solve my issue and will I get an error message?

and can I use the next release with a version tag right now?

@w3bdesign
Copy link

@w3bdesign Yes sorry, I fixed the config and still get the error. Will the next release solve my issue and will I get an error message?

and can I use the next release with a version tag right now?

@Kalo0m

I can't give a good answer to that yet, but apparently the Astro team is aware of the bug and has commited a fix.

I would check https://www.npmjs.com/package/@astrojs/vercel and wait until they get a new release published before trying to use it again.

@Kalo0m
Copy link
Author

Kalo0m commented Mar 3, 2023

It works perfectly with [email protected] thank you all !

@lirantal
Copy link

lirantal commented Mar 3, 2023

Note, this requires @astrojs/vercel to be updated too to at least 3.1.4

@MoustaphaDev
Copy link
Member

MoustaphaDev commented Mar 5, 2023

Closing as completed in #6380
As stated by the comments above, you need to update @astrojs/vercel and astro

@MoustaphaDev MoustaphaDev added the pkg: vercel Related to Vercel adapter (scope) label Mar 5, 2023
@lirantal
Copy link

lirantal commented Mar 5, 2023

Closing as completed in #6380 As stated by the comments above, you need to update astrojs/vercel and astro

@MoustaphaDev you should update your reply to not confuse folks to install a typosquatted package. it should be @astrojs/vercel and not astrojs/vercel (note the leading @ that denotes the official namespace)

@MoustaphaDev
Copy link
Member

Thanks @lirantal, updated!

jsjoeio referenced this issue in jsjoeio/speak-argentinian-spanish Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

No branches or pull requests

4 participants