I need some help in deploying my Flask/Vue.js web application.
Current setup: Vue.js frontend with vue-router with static pages + Flask backend (communicating over Ajax, only needed to facilitate sending an email through a form).
Problem:
I'm puzzled on how to deploy it on a VPS:
- Two processes on two different ports, one for uWsgi+Flask and one for Vue, with Nginx serving them
- One single process - Uswgi+Flask to serve the static (built) Vue pages, Nginx in front of them. Flask somehow needs to redirect the request to the appropriate static view.
- Something else
My Flask Backend/API:
from flask_cors import CORS
from flask_mail import Message
from datetime import datetime
import pytz
from flask_mail_sendgrid import MailSendGrid
from config import confreader
app = Flask(__name__)
app.config.from_object(confreader)
curdate = str(datetime.now(pytz.timezone("Europe/Bucharest")))
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
mail = MailSendGrid(app)
@app.route('/api/sendemail', methods=['POST'])
def send_email():
subject = '[Contact Form Message] ' + request.json['name'] + ' on ' + curdate
template = f"""
<h1>{request.json['name']} ({request.json['email']}) on {curdate}</h1>
<p>{request.json['text']}</p>"""
msg = Message(
subject,
recipients=[app.config['MAIL_DEFAULT_SENDER']],
html=template,
sender=request.json['email']
)
try:
mail.send(msg)
return jsonify(True)
except:
return jsonify(False)
if __name__ == '__main__':
app.run()
Thank you!