so my application is served by express locally with a flask API, so running
node server.js
and python runner.py
will initiate the frontend/backend.
However when deploying to heroku, only the frontend seems to work without any connection to the flask API, no backend resources get loaded.
This is my procfile with two dynos
web: node server.js
server: python runner.py
So when I navigate to the application after it has been deployed, just the frontend content is working.
However when I run python runner.py
on my local machine all the backend content on Heroku starts to work. I'm not really sure how or why that works, but I want Heroku to deal with hosting the API.
If anyone has any tips or advice I'd appriciate it.
Runner.py
import os
from flask import Flask, request, jsonify, json, render_template
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
# Runs the application
if __name__ == "__main__":
app.run(debug=True)
Server.js
const express = require('express');
const path = require('path');
const app = express();
app.use(express.static(__dirname + '/dist/client'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/client/index.html'));
});
app.listen(process.env.PORT || 8080);
Package.json scripts
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"heroku-postbuild": "ng build --prod"
}
Proxy.conf.json
{
"/api": {
"target": "http://localhost:5000",
"secure": false
}
}
Edit: May have found the issue - https://stackoverflow.com/a/54381386/12314065
Will give it a try and report back