HTTP port

Hi there. Any pointers on how to change the HTTP and HTTPS ports the server is listening on? 3000 and 3001 don't work for me.
8 Replies
kapa.ai
kapa.ai2mo ago
Hi @cmilazzo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you can change the ports that the Wasp server is listening on. Here are two main approaches: 1. Manually specify different ports: After the merge of this pull request (https://github.com/wasp-lang/wasp/pull/683), you can specify ports manually. For example, if you want to have the server run on 4040 and the web on 8000, you would specify the following environment variables in .env.client and .env.server respectively: In .env.client:
PORT=8000
REACT_APP_API_URL=<http://localhost:4040>

PORT=8000
REACT_APP_API_URL=<http://localhost:4040>

In .env.server:
PORT=4040
WASP_WEB_CLIENT_URL=<http://localhost:8000>

PORT=4040
WASP_WEB_CLIENT_URL=<http://localhost:8000>

Please note that it's not very clear in the docs which environment variables are available for configuration on the frontend. This is something that needs to be documented better. 2. Specify ports via CLI: Another easier way to choose these ports is by allowing them to specify ports via CLI, something like wasp start --web-client-port=8000 --api-server-port=4000. This feature is currently being discussed and is not yet implemented. Please note that these changes are not yet fully implemented and are part of an open issue on the Wasp Github (https://github.com/wasp-lang/wasp/issues/730). You can follow the issue for updates on when these changes will be available. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @cmilazzo, 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?
cmilazzo
cmilazzoOP2mo ago
@kapa.ai where are the .env.client and .env.server files located?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The .env.client and .env.server files are located at the root of your Wasp project. These files are used to define environment variables for your client and server respectively during development. Here's an example of how you might define variables in these files: In .env.server:
DATABASE_URL=postgresql://localhost:5432
SOME_VAR_NAME=somevalue
DATABASE_URL=postgresql://localhost:5432
SOME_VAR_NAME=somevalue
In .env.client:
REACT_APP_SOME_VAR_NAME=somevalue
REACT_APP_SOME_VAR_NAME=somevalue
These files should not be committed to version control, and they are already ignored by default in the .gitignore file that comes with Wasp. You can read more about this in the Wasp documentation (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-development). Please note that there was a closed issue (https://github.com/wasp-lang/wasp/issues/811) discussing moving these files to src/server and src/client respectively, but this change was not implemented. The files remain in the project's root directory. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @cmilazzo, 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?
cmilazzo
cmilazzoOP2mo ago
@kapa.ai how do I add an ssl port to the .env.client file?
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The .env.client file is used to set environment variables for the client-side of your Wasp application during development. However, specifying an SSL port directly in the .env.client file is not directly supported. Typically, the SSL configuration is handled by the server that's serving your application, not by the application itself. This could be a Node.js server, Nginx, Apache, or any other server you're using. If you're using a custom server configuration, you would typically specify the SSL port in the server's configuration, not in the .env.client file. You would also need to set up an SSL certificate for your server. If you're deploying your Wasp application, the platform you're deploying to (like Vercel, Netlify, or Heroku) would typically handle SSL for you. If you need to specify the URL of your server (including the SSL port if it's not the default 443) in your client-side code, you could add an environment variable to the .env.client file like this:
REACT_APP_SERVER_URL=<https://myserver.com:8443>
REACT_APP_SERVER_URL=<https://myserver.com:8443>
Then in your client-side code, you can access this variable as process.env.REACT_APP_SERVER_URL. Please note that any environment variable that you want to use in your client-side code must start with REACT_APP_. For more information on environment variables in Wasp, you can refer to the Wasp documentation (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-development). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @cmilazzo, 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?
Filip
Filip2mo ago
Hey @cmilazzo. This is a little tricky to do in development. I can still help you out if you needed, but the procedure is a little involved so let me know if you want us to get into it. May I ask why you need different ports in development? Usually, people want to change ports when deploying their app (and that is something Wasp will let do by default) and mistakenly think they need to change them in development as well.
cmilazzo
cmilazzoOP2mo ago
Hey @sodic I don't need to change in development. This is for my prod server. I did figure it out though (using the env variables)
Filip
Filip2mo ago
Oh, yeah, then it shouldn't be a problem Glad you got it working
Want results from more Discord servers?
Add your server