Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

API route not passing query string #9

Closed
wei opened this issue May 8, 2020 · 8 comments
Closed

API route not passing query string #9

wei opened this issue May 8, 2020 · 8 comments

Comments

@wei
Copy link

wei commented May 8, 2020

API route is not passing query string.

Repo:
https://github.com/wei/next-on-netlify-demo-wei

Example:
https://relaxed-mirzakhani-568b34.netlify.app/api/debug/12345?testqs=1

// api/debug/[id].js
export default async ( req, res ) => {
    res.json({ query: req.query });
    res.end();
};

Expected output

// npm run dev
{
    "query": {
        "testqs": "1",
        "id": "12345"
    }
}

Actual output

// npm run netlfy:dev
{
    "query": {
        "id": "12345"
    }
}
@FinnWoelm
Copy link
Collaborator

Hey @wei, great to hear from you again :)

Thanks for catching this issue! I'm working on a solution right now 🙂

I'll get back to you very soon!

@FinnWoelm
Copy link
Collaborator

Okay, I have some good news: The fix for this is relatively small!

Example: https://vigilant-lalande-4e2572.netlify.app/api/debug/12345?testqs=1&works=true
Code: https://github.com/FinnWoelm/next-on-netlify-demo-wei

Because it changes how things work, I would like to hold this commit back until the release of the upcoming next-on-netlify v2. I need to do a bit more work on a few things, so it may be another week or two until v2 comes out.

If you want to have query params right now, you can use the support-query-params branch:

npm install --save FinnWoelm/next-on-netlify#support-query-params

It has support for query params, but it's not a long-term branch. When I publish v2 of next-on-netlify, I'll notify you here and then delete that branch about ~30 days after. How does that sound?

Let's also keep this issue open for now 🙂

@wei
Copy link
Author

wei commented May 10, 2020

Thanks for the help!! Sounds great,I'll check it out. 😁

@FinnWoelm
Copy link
Collaborator

Hey @wei,

Quick status update: I'm still working on next-on-netlify v2. Support for query string parameters is now fully implemented. And I finally got around to writing tests with Jest and e2e tests with Cypress.

You may have noticed that the API endpoint you shared did not have the correct JSON content-type. This was due to multiValueHeaders which are not supported by Netlify. I filed an issue today: https://github.com/netlify/cli/issues/923

In the meantime, I've implemented a work-around for setting the correct headers (and any custom headers, too) by converting multiValueHeaders into plain headers. This will go live with the release of v2.

I would like tackle issues #2 and #7 before releasing v2, so please bear with me for a bit longer 😁

Hope you're doing well!
Finn

@wei
Copy link
Author

wei commented May 24, 2020

Thanks for keeping me posted! btw it looks like there is an extranuous

const multiValueHeaders = 

in the snippet from the issue you opened on netlify/cli.

@FinnWoelm
Copy link
Collaborator

Oops, great catch! Thanks! Fixed that ✔️

@laugharn
Copy link

Thanks for the work you're doing on this!

FinnWoelm added a commit that referenced this issue Jun 2, 2020
- **Breaking: You must change your `netlify.toml` configuration for
  next-on-netlify v2.0.0.** Please look at the README for the latest
  configuration.
  `next-on-netlify` now builds pre-rendered pages and static assets in
  `out_publish`. Netlify Functions for SSR pages are built to
  `out_functions`.
- Add support for `getStaticProps` (#7)
- Add support for `getStaticPaths` with and without fallback (#7)
- Add support for `getServerSideProps` (#7)
- Query string parameters are now correctly passed to Next Pages and API
  endpoints (#9)
- Response headers are now correctly set (#9)
- When a user encounters a 404, `next-on-netlify` now display the NextJS
  404 page rather than Netlify's default 404 page. You can customize the
  NextJS 404 page. (#2)
- Every page with server-side rendering is now converted to a
  stand-alone Netlify Function. Previously, all SSR pages were bundled
  in a single Netlify Function.
- `next-on-netlify` now prints out which pages are being converted to
  Netlify Functions for SSR, which pages are served as pre-rendered
  HTML, and the redirects that are being generated.
- Adding custom redirects via a `_redirects` file in the project root is
  no longer supported. Let me know if you want this back. Or define your
  redirects in `netlify.toml`.
@FinnWoelm
Copy link
Collaborator

Hey @wei,

next-on-netlify v2 is finally out 🎉 🎉 You can see the full list of changes in the changelog.

Thank you for your bug-hunting (and for catching my typos 😁)!

You'll need to make some changes to your netlify.toml for v2, both for deployment and for local preview:

# netlify.toml

[build]
  command   = "npm run build"
  functions = "out_functions"
  publish   = "out_publish"

[dev]
  functions = "out_functions"
  publish   = "out_publish"
  framework = "#static"

And you will want to adjust your .gitignore:

# .gitignore

# Files generated by next-on-netlify command
/out_publish/
/out_functions/
/404.html

Let me know if you run into any trouble. I closed this issue for now, but let's reopen it at any time if necessary! And if you build something awesome, let me know, too! I'd love to feature some real-world projects in the README.

Happy hacking! 🔥
Finn

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

No branches or pull requests

3 participants