I really “sorted” the problem. I have a directory called "smoke" (short for smoke and mirrors), and inside there I ran the angular-cli command:
ng new static
This created an angular-cli launcher application in a static directory. Then I created this (simplified) Python Flask application:
import os
from flask import Flask, send_from_directory, redirect
from flask.ext.restful import Api
from gevent import monkey, pywsgi
monkey.patch_all()
def create_app():
app = Flask("press_controller")
@app.route("/")
def home():
return redirect("/index.html")
@app.route("/<path:path>")
def root(path):
"""
This is the cheesy way I figured out to serve the Angular2 app created
by the angular-cli system. It essentially serves everything from
static/dist (the distribution directory created by angular-cli)
"""
return send_from_directory(os.path.join(os.getcwd(), "static/dist"), path)
return app
if __name__ == "__main__":
app = create_app()
server = pywsgi.WSGIServer(("0.0.0.0", 5000), app)
server.serve_forever()
else:
app = create_app()
That way I can go to http: // localhost: 5000 , and the application will serve the Angular application just like "ng serve". Now I can add the REST APIs to my endpoints as I wanted, and you have the services Angular to populate the application.
Arc
source
share