W
Wasp4mo ago
Conspyre

Deploying with Docker issues

I'm tryint to deploy the back-end with Docker on an Ubuntu box. I have the front end up via Apache, and the backend is reporting 404 on routes like /api/auth/me and /api/email/signup. I added a test route and I am able to hit it with curl via both localhost and the fully qualified DNS url - so that much is working. I went in and hacked the .wasp/build/server/src/server.ts to print the list of routes, and, it's pretty much empty. -------------------- ADDED THIS TO server.ts function printRoutes(app: Express) { console.log('Registered routes:'); app._router.stack.forEach((middleware) => { if (middleware.route) { // routes registered directly on the app console.log(${Object.keys(middleware.route.methods)} ${middleware.route.path}); } else if (middleware.name === 'router') { // router middleware middleware.handle.stack.forEach((handler) => { if (handler.route) { console.log(${Object.keys(handler.route.methods)} ${middleware.regexp} ${handler.route.path}); } }); } }); } // Call this function just before server.listen() printRoutes(app); --------------------------- SERVER LOG AT STARTUP: stripeMiddlewareFn is called Starting pg-boss... pg-boss started! Registered routes: get /^/?(?=/|$)/i / <------- AFAIK SHOULD BE ROUTES HERE Server listening on port 3001 This suggests that the wasp build has failed to produce any. Trying this solution on dev, it does not appear that this code path is hit so I'm not able to see routes. Suggestions?
7 Replies
kapa.ai
kapa.ai4mo ago
Hi @Conspyre. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the knowledge sources, it seems like there might be an issue with the way your routes are being registered in your Wasp application. However, the knowledge sources do not provide a direct solution to your problem. One thing to note is that you should generally avoid editing files in the .wasp directory directly, as these are compiled by Wasp and any changes you make might not persist. Instead, you should make changes in the src directory of your project root source (https://discord.com/channels/686873244791210014/1098429088164753498). If you're still having trouble, I would recommend trying to clean your Wasp project and starting it again. You can do this by running wasp clean followed by wasp start source (https://discord.com/channels/686873244791210014/1213958217537814640). If the issue persists, it might be helpful to check if there are any errors in your terminal or in the browser's developer tools console. These could provide more information about what might be going wrong source (https://discord.com/channels/686873244791210014/1213958217537814640). Finally, if you're still unable to resolve the issue, I would recommend reaching out to the Wasp community on their Discord server or opening an issue on the Wasp GitHub repository for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, 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?
Conspyre
ConspyreOP4mo ago
Running wasp clean/wasp build does not change the issue. @kapa.ai Deploying the back-end with Docker and the front end with Apache leads to a site that can't log in. Wasp provided auth routes are 404 to the front-end, and when they are called, nothing is logged in the server side (because apparently the routes are not being called). This is the exact build/deploy script used for the backend: Navigate to the Wasp build directory cd "$WASP_DIR/.wasp/build" Build the Docker image echo "Building Docker image..." sudo docker build -t app-backend . Stop and remove any existing container echo "Stopping and removing existing container (if any)..." sudo docker stop app-backend-container true sudo docker rm app-backend-container true Run the new container echo "Starting new container..." sudo docker run -d \ --name app-backend-container \ --env-file "$WASP_DIR/.env.server" \ -p 3001:3001 \ --restart unless-stopped \ app-backend
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the provided knowledge sources, it's not clear why the Wasp provided auth routes are returning 404. However, there are a few things you could check: 1. Environment Variables: Ensure that all necessary environment variables are correctly set up. This includes DATABASE_URL, WASP_WEB_CLIENT_URL, WASP_SERVER_URL, and JWT_SECRET if you're using Wasp's auth features. These should be set in your .env.server file source (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables). 2. Dockerfile: Make sure your Dockerfile is correctly set up to build the server. The Dockerfile should be located in the .wasp/build directory and should define an image for building the server source (https://wasp-lang.dev/docs/advanced/deployment/manually#2-deploying-the-api-server-backend). 3. Server URL: Ensure that the REACT_APP_API_URL environment variable is correctly set to the URL of the Wasp server when building the web client source (https://wasp-lang.dev/docs/advanced/deployment/manually#3-deploying-the-web-client-frontend). If you've checked all of these and the issue persists, it might be a good idea to reach out to the Wasp community on their Discord server or open an issue on the Wasp GitHub repository for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, 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?
Conspyre
ConspyreOP4mo ago
@kapa.ai I've now deployed the app three different ways, and I get the same error each way. 1) I can run the server with Docker. I get 404 errors on the /api/auth/email/signup and /api/auth/me routes 2) I can run the server with "node -r dotenv/config server.js dotenv_config_path=..." and the client will get the same 404 errors on the /api/auth/email/signup and /api/auth/me routes 3) I can run the server with "wasp start" and it's again running on port 3001, reverse proxied through Apache, and gives the same 404 errors on the /api/auth/email/signup and /api/auth/me routes When my server is running in any of the three modes, I can access my test route at https://my.site/api/test-route and it works. I can also access my test route at localhost:3001/api/test-route, in any of the configurations (Docker, node, wasp start) When I shut down the server in any of those modes, going to the https://my.site/login page and logging in, or https://my.site/signup and signing up - both of these change from a 404 error to a 503 error. What is causing my wasp-provided routes to go 404?
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the provided knowledge sources, it's not clear why the Wasp provided auth routes are returning 404. However, there are a few things you could check: 1. Port Configuration: Ensure that the server and client are running on the correct ports. The server usually runs on port 3001, while the client aims for port 3000. If another application is using these ports, it could cause issues source (https://discord.com/channels/686873244791210014/1204153431019753512). 2. Routing: Make sure your routes are correctly defined in your main.wasp file. Incorrectly defined routes could lead to 404 errors. Also, ensure that the routes are correctly ordered, as the order can affect which route is matched source (https://discord.com/channels/686873244791210014/1112653557934592022). 3. Database Connection: Ensure that your database is running and that Wasp can connect to it. If the database is not running, it could cause errors when trying to access routes that interact with the database source (https://github.com/wasp-lang/wasp/issues/1051). If you've checked all of these and the issue persists, it might be a good idea to reach out to the Wasp community on their Discord server or open an issue on the Wasp GitHub repository for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, 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?
Conspyre
ConspyreOP4mo ago
@kapa.ai I can't make progress deploying the app on my server. I'm back on to Railway. I've set the WASP_WEB_CLIENT_URL, WASP_SERVER_URL and redundantly the REACT_APP_WEB_CLIENT_URL and REACT_APP_API_URL to point to the assigned client and server URLs from Railway. The app is getting CORS errors hitting endpoints like /api/auth/me and so on. What is the solution to make wasp auth work on Railway?
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- To deploy your Wasp app on Railway and resolve CORS issues, you need to follow these steps: 1. Build your Wasp app: Run wasp build in your project directory. This will create a .wasp/build directory source (https://wasp-lang.dev/docs/advanced/deployment/manually#railway-server-client-and-database). 2. Deploy the server: Navigate to the .wasp/build directory and link your app build to your Railway project using railway link. Then, set up the required environment variables in the Railway dashboard. These include DATABASE_URL, WASP_WEB_CLIENT_URL, WASP_SERVER_URL, and JWT_SECRET. Finally, deploy the project using railway up source (https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-the-server). 3. Deploy the client: Navigate to the .wasp/build/web-app directory and link it to your Railway project. Then, configure Railway's static hosting for your client. This involves copying the build folder within the web-app directory to dist, and creating a Dockerfile and .dockerignore. Finally, deploy the client using railway up source (https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-the-client). 4. Set up domains: You need to generate domains for both the server and client services in the Railway dashboard. These domains should be used as the values for WASP_WEB_CLIENT_URL and WASP_SERVER_URL source (https://wasp-lang.dev/docs/advanced/deployment/manually#railway-server-client-and-database). If you're using an external authentication method supported by Wasp, such as Google or GitHub, make sure to additionally set the necessary environment variables specifically required by these methods source (https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-the-server). If you're still facing issues, it might be a good idea to reach out to the Wasp community on their Discord server or open an issue on the Wasp GitHub repository for further assistance. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Conspyre, 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?
Want results from more Discord servers?
Add your server