Closed msukmanowsky closed 4 years ago
You could try using Next's API routes instead to serve a JSON response from a specified url.
Otherwise, Zeit Now has some configuration options for Routes: https://zeit.co/docs/configuration/#routes
{
"routes": [{ "src": "/a" }]
}
Thanks @jamesmosier. API routes won't work for my use case (which by the way is a Shopify app).
Shopify adds some custom OAuth routes and a GraphQL proxy endpoint.
Tried adding that config but still have the same issue. Navigating to https://zeit-test.mikesukmanowsky.now.sh/a produces a 404 error.
I did some more thinking and you can combine the API routes and Now routing.
pages/api/a.js
now.json
to point to this API route:
{
"version": 2,
"routes": [
{ "src": "/a", "dest": "/api/a" }
]
}
@jamesmosier that does work, but the issue I have is that I need to use some Koa middleware and you can't really use those with the pages/api
based approach.
Ahhh I see. Then from the resources I found, a custom server and Now won't work together:
All the recommendations I saw were when needing 1 off API endpoints with Next & Now, either use the API routes and now.json routing or create pages that handle this in getInitialProps, both of which won't work if you need a more complex server setup with Koa.
Custom servers do not work on ZEIT Now. You'll need to use our built-in router and potentially the upcoming Custom Routes RFC: #9081.
We'll be removing most of the custom server examples soon-ish. They shouldn't be needed for most applications!
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Bug report
Describe the bug
Following the docs for custom server and routing, a simple
server.js
example runs locally but does not work when deploying to zeit.co.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
npm install
npm run dev
and navigate to http://localhost:3000/a (should show JSON response)npm run deploy
Expected behavior
Custom route
/a
should return JSON when deployed to zeit.co but it shows a 404 error.System information