[Python] Why does my Replit deployment work in Webview but fail to load on the production...

Discussão em 'Python' iniciado por Stack, Novembro 28, 2024.

  1. Stack

    Stack Membro Participativo

    I am deploying a web application on Replit using a Reserved VM deployment. While the app works perfectly in the Replit Webview (on ports like 3000 and 3001), it fails to load on the production domain (e.g., https://my-app.replit.app).

    Context:


    1. My .replit configuration includes the following:

      [deployment]
      run = ["npm", "start"]
      deploymentTarget = "gce"

      [[ports]]
      localPort = 80
      externalPort = 3000

      [[ports]]
      localPort = 3000
      externalPort = 3001

      [[ports]]
      localPort = 3001
      externalPort = 3002

      [[ports]]
      localPort = 5173
      externalPort = 80
      exposeLocalhost = true

      [[ports]]
      localPort = 8080
      externalPort = 8080

    2. My frontend uses Vite, and the vite.config.ts has:

      export default defineConfig({
      server: {
      host: '0.0.0.0',
      port: process.env.PORT || 3000,
      proxy: {
      '/api': {
      target: 'http://127.0.0.1:8080',
      changeOrigin: true,
      rewrite: (path) => path.replace(/^\/api/, ''),
      },
      },
      },
      });

    3. My backend (Python) runs on port 8080:

      app.run(host="0.0.0.0", port=8080)

    4. According to Replit's documentation for Reserved VM deployments:

      • HTTP requests are sent to external port 80.


      • The server must listen on 0.0.0.0 (not 127.0.0.1).


      • Port auto-detection will use the first opened port unless explicitly configured.
    Issues:


    • The app works in development but fails on the production domain.


    • Logs suggest the backend is running, but requests to the production domain do not connect to the app.


    • I suspect an issue with port mapping or traffic routing between frontend and backend
    What I've tried:


    1. Configuring PORT=8080 and host=0.0.0.0 in both frontend and backend.


    2. Explicitly mapping ports in .replit to expose 8080 as 80.


    3. Testing Webview ports (3000, 8080) which work locally.
    Question:


    How can I correctly configure my Replit deployment to ensure the application works on the production domain (https://my-app.replit.app) and properly routes traffic between frontend (Vite) and backend (Python)?

    Continue reading...

Compartilhe esta Página