python - 带有 Python 和 React.js 的单一可执行文件
问题描述
我有两个应用程序
- react.js + node.js 应用程序。
独立的python应用程序
我需要合并这两个应用程序并将这个应用程序分发到单个可执行文件/二进制文件中。我知道我需要摆脱 node.js 并使用 python 作为我的后端并将调用从 react-node 更改为 react-python。对于后者,我需要带的可能是 Flask。
对于打包,我可以使用 PyInstaller 或 cx_freeze。
任何指针什么是进行此合并和创建单个可执行文件/二进制文件的最佳方法,以便最终工作流程应如下所示:
1) 用户获取单个可执行文件/二进制文件
2) 运行/执行可执行文件/二进制文件
3)这会启动可以在浏览器上访问的应用程序
4) 用户将能够从 UI (React) 向后端 (Python) 发送请求
所以基本上单个可执行文件/二进制文件有 python env、python 后端和 react(UI) 代码。
解决方案
你可以使用这个设计结构来解决这个问题,就像所有的langs一样,你需要将前端打包到你的后端项目的public文件夹中:
.
└── project_template/
├── server/
└── static/
├── css/
├── images/
└── js/
这个项目模板可以是一个 npm 存储库,您可以自定义脚本来启动您的项目。
带有 react 和 node 的示例(您可以在GitHub 上查看 peoject ):
{
"name": "poker-hand-analyzer",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"install-frontend-dependencies": "cd ./frontend && yarn install",
"install-backend-dependencies": "cd ./backend && yarn install",
"install-dependencies": "yarn install-frontend-dependencies && yarn install-backend-dependencies && yarn install",
"frontend": "cd ./frontend && yarn start",
"backend": "cd ./backend && yarn start",
"start": "concurrently \"yarn frontend\" \"yarn backend\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/brunoxd13/poker-hand-analyzer.git"
},
"author": "Bruno Russi Lautenschlager",
"license": "ISC",
"bugs": {
"url": "https://github.com/brunoxd13/poker-hand-analyzer/issues"
},
"homepage": "https://github.com/brunoxd13/poker-hand-analyzer#readme",
"dependencies": {
"concurrently": "^4.1.0"
}
}
推荐阅读
- php - “未定义变量:利润 $sum-$sub”
- c# - Telerik - 我可以从数据库加载报告定义吗
- c++ - 用户定义的结构在声明时无法识别并给出类型错误
- mongodb - MongoDB 按填写了更多字段的文档排序
- airflow - Airflow - Xcoms 和并行作业 - 问题(xcoms 覆盖自己)
- python - 在创建的熊猫数据框中所做的更改不会反映在原始文件中吗?
- c# - System.Net.Sockets.SocketException:没有这样的主机是已知的
- python - 如何快速处理大型csv文件?
- outlook - Outlook 365 IMAP 是否有详细规范?它符合哪些 RFC?
- html - DIV 下的 SVG 对事件的反应