What is the API endpoint in production?
My development environment has port 3000 for the app and 3001 for api. When I deploy to production the site works but the API endpoint does not seem correct. What is the API endpoint in production?
4 Replies
Hi @Ghar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The API endpoint in production is determined by the URL of your server (the app's backend). Wasp automatically sets it during development when you run
wasp start
. In production, it should contain the value of your server's URL as the user's browser sees it (i.e., with the DNS and proxies considered).
You can access it like this:
This will log the API endpoint URL to the console.
Also, ensure that you have set the REACT_APP_API_URL
environment variable in your .env.client
file to the URL of your server. For example:
This is especially important if you are running your app in a production environment or if you have changed the default ports.
For more details, you can refer to the Wasp documentation on accessing the app configuration (https://wasp-lang.dev/docs/advanced/accessing-app-config#client-configuration-object).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Ghar, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?The API endpoint is the one your client uses to send its requests to - you can see this in the Network tab of the browser dev tools. Usually if you deploy your fly this is <your-app>-server.fly.dev.
Locally we use different ports like 3000 and 3001 to mean the client and the server. When we deploy stuff it’s usually different domains or subdomains that are used.
Thanks - If I use a custom domain, I should still send the API requests to <your-app>-server.fly.dev? Is that configured using the REACT_APP_API_URL
If I do that then I need to handle CORS?
We touch on that in the docs here: https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-a-wasp-app
If you set the env vars correctly, Wasp handles CORS for you 🙂
If you deploy to Fly via the Wasp CLI, there isn't much to worry about. If you're deploying manually - there answers in the docs as well.
Deploying Manually | Wasp
This document explains how to build and prepare your Wasp app for deployment.