W
Wasp-langβ€’3mo ago
lazi

Locally hosting two wasp projects at once

Hello! I'm trying to host two wasp projects locally (open on network) but it's deploying them on the same IP adresses. Is there any way to change that?
11 Replies
MEE6
MEE6β€’3mo ago
Wohooo @lazi, you just became a Waspeteer level 7!
kapa.ai
kapa.aiβ€’3mo ago
Hi @lazi. 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 host two Wasp projects locally at the same time by changing the ports they use. By default, Wasp uses port 3001 for the API server (backend) and 3000 for the web app (frontend). If these ports are already taken, wasp start will fail. There are two main solution approaches: 1. Allow user to pick different ports manually. 2. Have Wasp dynamically search for open ports and use those. For the first approach, you can specify ports manually. For example, if you want to have the server run on 4040 and web on 8000, you would specify the following environment variables in .env.client:
PORT=8000
REACT_APP_API_URL=<http://localhost:4040>
PORT=8000
REACT_APP_API_URL=<http://localhost:4040>
And specify the following environment variables in .env.server:
PORT=4040
WASP_WEB_CLIENT_URL=<http://localhost:8000>
PORT=4040
WASP_WEB_CLIENT_URL=<http://localhost:8000>
For the second approach, Wasp could, from Wasp CLI code, look for ports, identify open ones, and then make sure that web client and API server use those. This way, Wasp would choose the ports dynamically. However, this feature is not yet implemented in Wasp. Please note that these changes will allow you to run two Wasp projects at the same time on your local machine, but they will still be hosted on the same IP address (localhost), just on different ports. For more details, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/730). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @lazi, 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?
lazi
laziOPβ€’3mo ago
@kapa.ai well, the ports are certainly already taken but wasp start did not fail at all
kapa.ai
kapa.aiβ€’3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- If wasp start did not fail, it's possible that the ports were not actually taken, or the processes using those ports were not active at the time you ran the command. However, if you're certain that the ports were occupied and wasp start still ran successfully, it might be a bug or an unexpected behavior. In the current version of Wasp, if ports 3000 (for the frontend) and 3001 (for the backend) are occupied, wasp start should fail. This is because Wasp has these ports hardcoded for use and does not yet have the functionality to dynamically choose available ports if the default ones are taken. If you're experiencing issues with this, I would recommend manually specifying different ports for your Wasp projects as described in my previous response. This should allow you to run multiple Wasp projects at the same time without port conflicts. For more information, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/730). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @lazi, 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
Filipβ€’3mo ago
Hey @lazi, Just to clear something up first. If you're running apps on a local computer that only has a single network interface, all of them will run on the same IP address (localhost for the your computer, and the computer's network IP for other computers), there's no simple way to change this (with Wasp or otherwise). If your computer has multiple network interfaces (e.g., two ethernet cables, an ethernet and a wifi, etc.), then there is a way to do this, but it's a little involved and a little weird (seems too low-level for your use case). So, if you just want to run two apps without interfering on the same computer, I recommend doing so through different ports instead of different IP addresses. Would that work for you?
miho
mihoβ€’3mo ago
@lazi are you talking here about hosting two production apps? What's your setup, a VPS? Are you using Docker to run the apps? In that case you can simply forward the 3000 and 3001 ports to different values that your reverse proxy can then use.
lazi
laziOPβ€’3mo ago
Yep, different ports should do! I think the problem was that - i only have a single network interface I'm kind of a noobie when it comes to networking - i'm simply running proof-of-concept prototypes and wanted to share with the team I ended up hosting it on Fly/Netlify directly πŸ˜„
Filip
Filipβ€’3mo ago
From what I got, @lazi was running the apps locally and wanted to share them on the local network. @lazi Glad you got the fly deploy working, that's probably the easiest way to go about it. If you do end up needing different ports, I can help you out with a guide, so let me know. @miho We really should make running wasp on different ports easier than it is. I'll make an issue if we don't already have ine
miho
mihoβ€’3mo ago
I believe that the server honors the PORT env var and that the client can be adjusted with the vite.config.ts file πŸ˜„ but then ... you need to update the env vars for both the server and the client to be aware of the new URLs! Maybe that's not even possible in dev since we rely on the defaults so much. Any ho, create an issue and let's tackle this πŸ™‚
Filip
Filipβ€’3mo ago
Will do! And it is possible (tried it this morning), but it took me 20 minutes to set it up, so for the users it's even worse πŸ˜…
Filip
Filipβ€’3mo ago
GitHub
Make it easy to use different ports (than 3000 and 3001) during Was...
Right now, Wasp has it hardcoded to use 3001 port for api server (backend) and 3000 for web app (frontend). If those ports are already taken, wasp start will fail. This causes problems in different...
Want results from more Discord servers?
Add your server