Eric Nelson Eric Nelson - 3 years ago 103
Apache Configuration Question

Best practice for running an Angular app which calls a Flask RESTful API

In this tutorial, they created an API using flask which you can post to and it will give a response.

It then tells you to make an Angular app which makes calls to the API.

How would this work on an apache server?

The tutorial doesn't mention this, but I've tried using a WSGI on apache that can run a flask file which can redirect to the angular app using

@app.route('/')
def index():
return render_template('index.html',content=content)


Is this a typical way to deploy an Angular and Flask app? It seems weird that the flask is calling the angular index.html, is there a way to do this with lower coupling?

What is the standard for using Flask as a RESTful API and also running angular on the same server?

Answer Source

Flask is a web framework and play the role of WSGI application in the protocol of WSGI. It needs a WSGI server to negotiate with http clients and then call your WSGI app to process http requests. Although Flask ships with a small WSGI server for development, you should use WSGI servers like gunicorn in production.

Angular app consists of static files which should be served by a http server. Nginx is the best http server for static files. But for simplicity, Flask plus WSGI server can serve these static files for you. So you will see

the flask is calling the angular index.html

When it comes to your questions

Is this a typical way to deploy an Angular and Flask app?

It's a typical way in development but not production.

is there a way to do this with lower coupling? What is the standard for using Flask as a RESTful API and also running angular on the same server?

  1. Serve angular files by Nginx.
  2. Use gunicorn or other WSGI servers to serve Flask app.
  3. It's also a good practice to use Nginx as proxy for WSGI server.

Any question?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download