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

Configure API to work on Vercel from Next SSR #41

Merged
merged 1 commit into from
Dec 2, 2023
Merged

Conversation

taesungh
Copy link
Member

Changes

  • Set up axios instance to use correct public Vercel URL for API calls during server-side rendering
    • Inject user's client-side cookies during API request
  • Create demo example to illustrate server-side API call with axios and a native POST request from the client
  • Update Uvicorn host to resolve IPv6 issues
  • Configure Next rewrite which acts like a Vercel rewrite
    • This allows for local client-side testing of API endpoints and makes the API paths publicly accessible at /api/

Testing

Clone the branch locally and visit /demo while also having the local API server running with Uvicorn

  • Observe the dynamic response text when providing a cookie with the name username
  • Try entering a number in the input field and submitting the form

Visit /demo in the deployed preview

  • Observe the same behavior as in the development environment

- Set up axios instance to use correct public Vercel URL for API calls
  during server-side rendering
  - Inject user's client-side cookies during API request
- Create demo example to illustrate server-side API call with axios and
  a native POST request from the client
- Update Uvicorn `host` to resolve IPv6 issues
- Configure Next rewrite which acts like a Vercel rewrite
  - This allows for local client-side testing of API endpoints and makes
    the API paths publicly accessible at `/api/`
@taesungh taesungh requested a review from a team November 28, 2023 06:35
Copy link
Contributor

Deploy preview for irvinehacks-site-2024 ready!

Name IrvineHacks 2024 Site
Preview Visit Preview
Commit c116ab1

Copy link
Contributor

Deploy preview for irvinehacks-site-2024-sanity ready!

Name Sanity Studio
Preview Visit Preview
Commit c116ab1

Copy link
Contributor

@waalbert waalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@samderanova samderanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waalbert was dealing with an Axios error related to IPv6 though (ECONNREFUSED ::1:8000) until he removed the ::1 entry from /etc/hosts. I'm pretty sure this isn't the proper way to resolve the error, but you did already change the Uvicorn host to localhost so I'm not too sure what the issue is here. To make matters even more peculiar, I'm not able to replicate the same error on my machine, perhaps due to an operating system/networking difference.

@taesungh
Copy link
Member Author

taesungh commented Dec 1, 2023

Interesting, on my machine, Node v16 resolves localhost to IPv4 whereas Node v17, v18, and v19 resolve IPv6 first, but interestingly Node v20 resolves IPv4 first. None of the versions seem to respect the order of the hosts file.

@samderanova
Copy link
Contributor

Ok that makes more sense. Currently, I'm on Node 20.

@samderanova samderanova merged commit acfd79a into main Dec 2, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

3 participants