Search code examples
node.jsnpmaxiosnuxt.jshttp-proxy

Proxy module doesn't work when serving nuxt app statically


So, Iv'e been trying to setup a small example of a server with 2 factor authentication features. I'm using nuxt as the frontend and flask as the backend.

While developing locally (using npm run dev) I was able to get the chain of communication to work:

  1. The webpage sends a request to server/<some_request>/<some_param>
  2. The proxy module redirects it to http://localhost:5000/<some_request>/<some_param>
  3. The request is sent by the axios module
  4. flask receives the request, processes it and answers.

When trying to deploy this application to a dreamhost server, I used npm run build and npm run generate to serve the website statically. I was able to receive my webpage when browsing.

But when trying to login, the chain described above broke, and requests to server/<some_request>/<some_param> were answered with 404. In the server's command line I saw that flask didn't receive any request, so I assume that this is some issue with the proxy module.

I'm not really sure how to debug this problem, so any help or ideas will be appreciated.


Solution

  • Okay, so I got everything working, and here are my conclusions:

    1. The proxy module, makes the redirection in the client side, meaning that I would be trying to access my own machine when redirecting to localhost:5000, rather than to the server.
    2. The proxy module can't be used when using npm run generate (there's a warning that says it's disabled).
    3. Since I wanted to redirect to flask from the client side (browser), I couldn't just run it as is. I had to register another subdomain and use Passenger to deploy my app (A guide to enabling passenger, getting started with python in passenger and A great guide to deploying flask over passenger).