I'm trying to push a program containing of 2 apps to Cloudfoundry - a Flask server to run a Python API and a Polymer app for frontend. Currently I'm using the following structure:
manifest.yml
:
---
applications:
- name: flask_min
path: ./flask_min
buildpack: https://github.com/cloudfoundry/python-buildpack
memory: 512M
- name: pacing_app
memory: 512M
buildpack: nodejs_buildpack
command: node server/app.js
path: ./pacing_app/build/es5-basic
And then in the folder ./flask_min
I have a Procfile
:
web: python3 app.py
and app.py
has a Flask server (plus the decorator for CORS for local testing that I left out from here for brevity):
app = Flask(__name__)
port = int(os.getenv("PORT", 7733))
@app.route('/hello', methods=['GET', 'OPTIONS'])
@crossdomain(origin='*')
def hello():
return "Hello"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port)
I can cf push
it, and the instances show up running. However, when I visit the url of the flask_min app, I don't get the "Hello" it's supposed to print out, I get an HTTP ERROR 503
.
As for the pacing_app, I am using the Predix Webapp Starter, except that I removed the elements in seed-app.html
and just replaced it with the API call:
<template>
<iron-ajax url="http://localhost:7733/hello" handle-as="text" last-response="{{data}}" auto></iron-ajax>
<p>{{data}}</p>
</template>
Locally this is working, however, on Predix it is not. First question is: How can I link to the Flask API once it's on Predix?
Also, even though the whole thing is working locally, the Polymer frontend also won't load when on Predix. I also get
Failed to load resource: the server responded with a status of 503 (Service Unavailable)
Even though the cf push
seems successful, the same IS running locally when I do a gulp
in the pacing-app
folder and run thy python server "by hand" locally.
Do you know what I'm doing wrong? How can I set up a Polymer frontend with Predix components that uses a Python API also running on Predix?
I'm not set on using two separate apps, I just don't know how to do this with one app. I would prefer to have the Polymer app run on the NodeJS server instead of serving it from Flask because of performance and the Python/Flask server is important because I intend to run some SKLearn code in the background.