简体   繁体   English

如何编写入门脚本来启动我的后端和前端?

[英]How to write a starter script to start my backend and frontend?

I running python flask as my backend and react as my frontend. 我将python flask作为后端运行,并作为前端进行响应。 Every time I start my app, I have to run export FLASK_APP=app and then flask start in terminal 1 and npm start in terminal 2. How do I write a single script that starts both processes? 每次启动我的应用程序时,都必须运行export FLASK_APP=app ,然后在终端1 flask start在终端2 flask start npm start 。如何编写一个启动两个进程的脚本? Here is my attempt: 这是我的尝试:

#!/bin/bash
export FLASK_APP=microblog.py
flask run > /dev/null
npm start --prefix ~/app

Try this: 尝试这个:

#!/bin/bash
export FLASK_APP=microblog.py
flask run > /dev/null & pids=$!
npm start --prefix ~/app & pids+=" $!"

trap "kill $pids" SIGTERM SIGINT
wait $pids

This script starts both flask and npm in background, and stores their PIDs. 该脚本在后台启动flask和npm,并存储它们的PID。 After that, we set up a trap - in case you hit CTRL - C , both programs will get killed. 之后,我们设置了一个陷阱-如果您按CTRL - C ,则两个程序都将被杀死。 The wait line will block until both the flask and npm process has finished - so you can easily terminate both with CTRL-C . wait行将阻塞,直到flask和npm过程都完成为止-因此您可以使用CTRL-C轻松终止两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 同时启动后端和前端的脚本 - A script to start backend and frontend at the same time Django REST 框架 - 如何在前端事件发生后在后端启动函数 - Django REST Framework - how to start functions on backend after event on frontend 如何保护自己的仅服务于我的前端的后端 API? - How to secure own backend API which serves only my frontend? 如何将后端 Flask 微服务与前端 Flask 代码连接起来? - how do I connect my backend flask micro services with my frontend flask code? 如何结合 javascript/react 前端和 python 后端? - How to combine javascript/react frontend and python backend? 如何在后台使用bokeh.js前端连接全息视图 - How to connect holoviews in backend with bokehjs frontend 使用 Flask 将我的 Python 后端与我的 Flutter 前端连接起来 - Connecting my Python backend with my Flutter Frontend using Flask 我的 Kivy 应用程序中的哪些部分对应于后端和前端 - What parts in my Kivy application corresponds to the backend and their frontend 如何将完整的Vue.js应用程序(前端)连接到Django(后端) - How to connect a completed Vue.js app (frontend) to Django (backend) 如何将列表从 flask 后端传递到 reactjs 前端? - how to pass a list from flask backend to a reactjs frontend?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM