graphxr-database-proxy 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphxr_database_proxy-1.0.0/LICENSE +21 -0
- graphxr_database_proxy-1.0.0/MANIFEST.in +28 -0
- graphxr_database_proxy-1.0.0/PKG-INFO +180 -0
- graphxr_database_proxy-1.0.0/doc/DEV_GUIDE.md +60 -0
- graphxr_database_proxy-1.0.0/doc/DEV_GUIDE.zh.md +60 -0
- graphxr_database_proxy-1.0.0/doc/FRONTEND_INTEGRATION.md +183 -0
- graphxr_database_proxy-1.0.0/doc/PYPI_PUBLISHING.md +361 -0
- graphxr_database_proxy-1.0.0/doc/RELEASE_CHECKLIST.md +86 -0
- graphxr_database_proxy-1.0.0/doc/USAGE.md +194 -0
- graphxr_database_proxy-1.0.0/doc/USAGE.zh.md +204 -0
- graphxr_database_proxy-1.0.0/examples/auth_methods_example.py +296 -0
- graphxr_database_proxy-1.0.0/examples/env_variables_example.py +301 -0
- graphxr_database_proxy-1.0.0/examples/future_database_support.py +222 -0
- graphxr_database_proxy-1.0.0/examples/get_project_apis_example.py +239 -0
- graphxr_database_proxy-1.0.0/examples/python.test.py +26 -0
- graphxr_database_proxy-1.0.0/examples/python_api_example.py +294 -0
- graphxr_database_proxy-1.0.0/examples/quick_start.py +94 -0
- graphxr_database_proxy-1.0.0/pyproject.toml +87 -0
- graphxr_database_proxy-1.0.0/readme.md +136 -0
- graphxr_database_proxy-1.0.0/readme.zh.md +168 -0
- graphxr_database_proxy-1.0.0/requirements.txt +10 -0
- graphxr_database_proxy-1.0.0/setup.cfg +4 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/__init__.py +16 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/api/__init__.py +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/api/database.py +266 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/api/google.py +437 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/api/projects.py +99 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/common/util.py +38 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/drivers/__init__.py +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/drivers/base.py +56 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/drivers/factory.py +36 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/drivers/spanner.py +814 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/main.py +110 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/models/__init__.py +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/models/google.py +50 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/models/project.py +170 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/proxy.py +495 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/proxyForDev.py +290 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/services/__init__.py +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/services/project_service.py +150 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/favicon.ico +0 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/index.html +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/main.7391ee9773c403483393.css +175 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/main.7391ee9773c403483393.css.map +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/main.ce3fbb85a7bc9452edb9.js +2 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/main.ce3fbb85a7bc9452edb9.js.map +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/vendors.70542a99f336a8021013.js +3 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/vendors.70542a99f336a8021013.js.LICENSE.txt +95 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy/static/vendors.70542a99f336a8021013.js.map +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy.egg-info/PKG-INFO +180 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy.egg-info/SOURCES.txt +54 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy.egg-info/dependency_links.txt +1 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy.egg-info/entry_points.txt +2 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy.egg-info/requires.txt +25 -0
- graphxr_database_proxy-1.0.0/src/graphxr_database_proxy.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kineviz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# 包含静态文件
|
|
2
|
+
recursive-include src/graphxr_database_proxy/static *
|
|
3
|
+
|
|
4
|
+
# 包含文档文件
|
|
5
|
+
include README.md
|
|
6
|
+
include LICENSE
|
|
7
|
+
include *.md
|
|
8
|
+
|
|
9
|
+
# 包含配置文件
|
|
10
|
+
include pyproject.toml
|
|
11
|
+
include requirements.txt
|
|
12
|
+
|
|
13
|
+
# 包含示例和文档
|
|
14
|
+
recursive-include examples *.py
|
|
15
|
+
recursive-include doc *.md
|
|
16
|
+
|
|
17
|
+
# 排除不需要的文件
|
|
18
|
+
global-exclude *.pyc
|
|
19
|
+
global-exclude *.pyo
|
|
20
|
+
global-exclude *~
|
|
21
|
+
global-exclude .git*
|
|
22
|
+
global-exclude .env*
|
|
23
|
+
prune .venv
|
|
24
|
+
prune __pycache__
|
|
25
|
+
prune .pytest_cache
|
|
26
|
+
prune node_modules
|
|
27
|
+
prune frontend/node_modules
|
|
28
|
+
prune frontend/.webpack-cache
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphxr-database-proxy
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: GraphXR Database Proxy - Secure middleware for connecting GraphXR to databases
|
|
5
|
+
Author-email: Sean Li <sean@kineviz.com>, Kineviz <support@kineviz.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Kineviz/graphxr-database-proxy
|
|
8
|
+
Project-URL: Documentation, https://docs.kineviz.com/graphxr-database-proxy
|
|
9
|
+
Project-URL: Repository, https://github.com/Kineviz/graphxr-database-proxy
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/Kineviz/graphxr-database-proxy/issues
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Requires-Python: >=3.8
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: fastapi>=0.104.0
|
|
22
|
+
Requires-Dist: uvicorn[standard]>=0.24.0
|
|
23
|
+
Requires-Dist: pydantic>=2.0.0
|
|
24
|
+
Requires-Dist: python-multipart>=0.0.6
|
|
25
|
+
Requires-Dist: google-cloud-spanner>=3.40.0
|
|
26
|
+
Requires-Dist: google-auth-oauthlib>=1.0.0
|
|
27
|
+
Requires-Dist: google-auth>=2.0.0
|
|
28
|
+
Requires-Dist: aiofiles>=23.0.0
|
|
29
|
+
Requires-Dist: pyyaml>=6.0
|
|
30
|
+
Provides-Extra: ui
|
|
31
|
+
Requires-Dist: aiofiles>=23.0.0; extra == "ui"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
38
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=1.5.0; extra == "dev"
|
|
40
|
+
Requires-Dist: pre-commit>=3.0.0; extra == "dev"
|
|
41
|
+
Provides-Extra: all
|
|
42
|
+
Requires-Dist: graphxr-database-proxy[dev,ui]; extra == "all"
|
|
43
|
+
Dynamic: license-file
|
|
44
|
+
|
|
45
|
+
# GraphXR Database Proxy
|
|
46
|
+
|
|
47
|
+
[](LICENSE)
|
|
48
|
+
[](https://python.org)
|
|
49
|
+
[](https://fastapi.tiangolo.com)
|
|
50
|
+
|
|
51
|
+
> **Language**: [English](https://github.com/Kineviz/graphxr-database-proxy/readme.md) | [中文](https://github.com/Kineviz/graphxr-database-proxy/readme.zh.md)
|
|
52
|
+
|
|
53
|
+
A secure middleware that connects [GraphXR](https://www.kineviz.com/graphxr) to various backend databases with zero trust architecture.
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
- **Zero Trust Security**: Strict authentication and authorization at the proxy layer
|
|
58
|
+
- **Direct Browser Connectivity**: REST/GraphQL APIs for efficient data access
|
|
59
|
+
- **Multi-Database Support**: Spanner Graph, Neo4j, and more
|
|
60
|
+
- **Open Source**: Fully auditable and customizable
|
|
61
|
+
- **Pure Python**: Easy to deploy and maintain
|
|
62
|
+
|
|
63
|
+
## ⚡ Quick Start for Spanner Graph
|
|
64
|
+
|
|
65
|
+
1. Run the following commands to start graphxr-database-proxy (requires [uv](https://docs.astral.sh/uv/), [node.js](https://nodejs.org/en/download/))
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
git clone https://github.com/Kineviz/graphxr-database-proxy.git
|
|
69
|
+
cd graphxr-database-proxy
|
|
70
|
+
uv venv
|
|
71
|
+
source .venv/bin/activate # or .venv/bin/activate on Windows
|
|
72
|
+
uv pip install -e ".[ui]"
|
|
73
|
+
uv pip install -r requirements.txt
|
|
74
|
+
cd frontend && npm install && npm run build && cd -
|
|
75
|
+
graphxr-proxy --ui
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. Visit http://localhost:9080/
|
|
79
|
+
3. Click "Create New Project"
|
|
80
|
+
4. Project Name: "Test"
|
|
81
|
+
5. Database Type: "Google Cloud Spanner"
|
|
82
|
+
6. Authentication Type: "Service Account"
|
|
83
|
+
7. Upload the credential file you exported from GCP Console or gcloud CLI. [Export Instructions](https://github.com/Kineviz/try-graphxr-spannergraph#)
|
|
84
|
+
8. Select "Instance ID" e.g. "demo"
|
|
85
|
+
9. Select "Database ID" e.g. "cymbal"
|
|
86
|
+
10. Select "Property Graph" e.g. "ECommerceGraph"
|
|
87
|
+
11. Click "Create"
|
|
88
|
+
12. For the new project, under Actions, copy the API URL. e.g. "http://localhost:9080/api/spanner/Test"
|
|
89
|
+
13. Go back to GraphXR's Create Project wizard and paste the API URL into GraphXR for a project with a "Database Proxy" database type.
|
|
90
|
+
|
|
91
|
+
## Other ways to start graphxr-database-proxy
|
|
92
|
+
|
|
93
|
+
### Install
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Install from PyPI
|
|
97
|
+
pip install graphxr-database-proxy[ui]
|
|
98
|
+
|
|
99
|
+
# Or from source
|
|
100
|
+
git clone https://github.com/Kineviz/graphxr-database-proxy.git
|
|
101
|
+
cd graphxr-database-proxy
|
|
102
|
+
uv venv
|
|
103
|
+
source .venv/bin/activate # or .venv/bin/activate on Windows
|
|
104
|
+
uv pip install -e ".[ui]"
|
|
105
|
+
uv pip install -r requirements.txt
|
|
106
|
+
cd frontend && npm install && npm run build && cd -
|
|
107
|
+
pip install -e .[ui]
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Configure & Run
|
|
111
|
+
|
|
112
|
+
**Option 1: Web UI (Recommended)**
|
|
113
|
+
```bash
|
|
114
|
+
graphxr-proxy --ui
|
|
115
|
+
```
|
|
116
|
+
> Open http://localhost:9080/admin for configuration
|
|
117
|
+
|
|
118
|
+
**Option 2: Python Code**
|
|
119
|
+
```python
|
|
120
|
+
from graphxr_database_proxy import DatabaseProxy
|
|
121
|
+
|
|
122
|
+
proxy = DatabaseProxy()
|
|
123
|
+
|
|
124
|
+
service_account_json = {
|
|
125
|
+
"type": "service_account",
|
|
126
|
+
"project_id": "your-gcp-project-id",
|
|
127
|
+
"private_key": "-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----\\n",
|
|
128
|
+
"client_email": "your-service-account@your-gcp-project-id.iam.gserviceaccount.com",
|
|
129
|
+
...
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
project_id = proxy.add_project(
|
|
133
|
+
project_name="project_name",
|
|
134
|
+
database_type="spanner",
|
|
135
|
+
project_id="gcp-project-id",
|
|
136
|
+
instance_id="spanner-instance-id",
|
|
137
|
+
database_id="spanner-database-id",
|
|
138
|
+
credentials=service_account_json,
|
|
139
|
+
graph_name="graph_name" # Optional
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
proxy.start(
|
|
143
|
+
host="0.0.0.0",
|
|
144
|
+
port=9080,
|
|
145
|
+
show_apis=True
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## 🐳 Docker
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
docker run -d -p 9080:9080 \
|
|
153
|
+
--name graphxr-database-proxy \
|
|
154
|
+
-v ${HOME}/graphxr-database-proxy/config:/app/config \
|
|
155
|
+
kineviz/graphxr-database-proxy:latest
|
|
156
|
+
```
|
|
157
|
+
> You can visit http://localhost:9080/admin for configuration after starting the container.
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## 🤝 Contributing
|
|
162
|
+
|
|
163
|
+
1. Fork the repository
|
|
164
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
165
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
166
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
167
|
+
5. Open a Pull Request
|
|
168
|
+
|
|
169
|
+
## 📄 License
|
|
170
|
+
|
|
171
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
172
|
+
|
|
173
|
+
## 🆘 Support
|
|
174
|
+
|
|
175
|
+
- 🐛 [Issue Tracker](https://github.com/Kineviz/graphxr-database-proxy/issues)
|
|
176
|
+
- 📧 Email: support@kineviz.com
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
**Built with ❤️ by [Kineviz](https://www.kineviz.com)**
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Development Environment Guide
|
|
2
|
+
|
|
3
|
+
> **Language**: [English](https://github.com/Kineviz/graphxr-database-proxy/doc/DEV_GUIDE.md) | [中文](https://github.com/Kineviz/graphxr-database-proxy/doc/DEV_GUIDE.zh.md)
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
### One-Click Development Environment
|
|
8
|
+
```bash
|
|
9
|
+
npm run dev # Start both frontend and backend (recommended)
|
|
10
|
+
```
|
|
11
|
+
This command will start:
|
|
12
|
+
- **Backend Server** (Python FastAPI): http://localhost:9080
|
|
13
|
+
- **Frontend Development Server** (React): http://localhost:3002
|
|
14
|
+
|
|
15
|
+
### Start Services Separately
|
|
16
|
+
```bash
|
|
17
|
+
npm run dev:backend # Start backend only
|
|
18
|
+
npm run dev:frontend # Start frontend only
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 🔧 Development Environment Features
|
|
23
|
+
|
|
24
|
+
### Hot Reload
|
|
25
|
+
- **Python Code Changes**: Backend server automatically restarts
|
|
26
|
+
- **React Component Changes**: Browser automatically refreshes, maintains state
|
|
27
|
+
- **Configuration File Changes**: Automatically detects and restarts appropriate services
|
|
28
|
+
|
|
29
|
+
### Monitored File Types
|
|
30
|
+
- **Backend**: `.py`, `.json`, `.toml`, `.txt` files
|
|
31
|
+
- **Frontend**: `.js`, `.jsx`, `.ts`, `.tsx`, `.css`, `.scss` files
|
|
32
|
+
|
|
33
|
+
### Port Configuration
|
|
34
|
+
- **Backend API**: 9080
|
|
35
|
+
- **Frontend Development Server**: 3002 (automatically proxies API to 9080)
|
|
36
|
+
- **API Documentation**: http://localhost:9080/docs
|
|
37
|
+
|
|
38
|
+
## 🐛 Development Debugging
|
|
39
|
+
|
|
40
|
+
### View Logs
|
|
41
|
+
Development environment displays detailed log information:
|
|
42
|
+
- **Backend Logs**: uvicorn + FastAPI request logs
|
|
43
|
+
- **Frontend Logs**: webpack build and hot reload logs
|
|
44
|
+
|
|
45
|
+
### Restart Services
|
|
46
|
+
In the nodemon console, type `rs` to manually restart the backend service.
|
|
47
|
+
|
|
48
|
+
### Common Issues
|
|
49
|
+
1. **Port Conflict**: Ensure ports 9080 and 3002 are not occupied by other programs
|
|
50
|
+
2. **Virtual Environment**: Ensure `.venv` directory exists and contains correct Python environment
|
|
51
|
+
3. **Dependency Installation**: Run `npm install` to ensure all dependencies are installed
|
|
52
|
+
|
|
53
|
+
## 📁 Project Structure
|
|
54
|
+
```
|
|
55
|
+
├── src/ # Python backend source code
|
|
56
|
+
├── frontend/ # React frontend source code
|
|
57
|
+
├── config/ # Configuration files
|
|
58
|
+
├── nodemon.json # nodemon configuration
|
|
59
|
+
└── package.json # npm scripts and dependencies
|
|
60
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# 开发环境指南
|
|
2
|
+
|
|
3
|
+
> **语言**: [English](DEV_GUIDE.md) | [中文](DEV_GUIDE.zh.md)
|
|
4
|
+
|
|
5
|
+
## 🚀 快速开始
|
|
6
|
+
|
|
7
|
+
### 一键启动开发环境
|
|
8
|
+
```bash
|
|
9
|
+
npm run dev # 同时启动前后端 (推荐)
|
|
10
|
+
```
|
|
11
|
+
这个命令会同时启动:
|
|
12
|
+
- **后端服务器** (Python FastAPI): http://localhost:9080
|
|
13
|
+
- **前端开发服务器** (React): http://localhost:3002
|
|
14
|
+
|
|
15
|
+
### 分别启动服务
|
|
16
|
+
```bash
|
|
17
|
+
npm run dev:backend # 只启动后端
|
|
18
|
+
npm run dev:frontend # 只启动前端
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 🔧 开发环境特性
|
|
23
|
+
|
|
24
|
+
### 热重载 (Hot Reload)
|
|
25
|
+
- **Python 代码修改**: 后端服务器自动重启
|
|
26
|
+
- **React 组件修改**: 浏览器自动刷新,保持状态
|
|
27
|
+
- **配置文件修改**: 自动检测并重启相应服务
|
|
28
|
+
|
|
29
|
+
### 监控的文件类型
|
|
30
|
+
- **后端**: `.py`, `.json`, `.toml`, `.txt` 文件
|
|
31
|
+
- **前端**: `.js`, `.jsx`, `.ts`, `.tsx`, `.css`, `.scss` 文件
|
|
32
|
+
|
|
33
|
+
### 端口配置
|
|
34
|
+
- **后端 API**: 9080
|
|
35
|
+
- **前端开发服务器**: 3002 (自动代理API到9080)
|
|
36
|
+
- **API 文档**: http://localhost:9080/docs
|
|
37
|
+
|
|
38
|
+
## 🐛 开发调试
|
|
39
|
+
|
|
40
|
+
### 查看日志
|
|
41
|
+
开发环境会显示详细的日志信息:
|
|
42
|
+
- **后端日志**: uvicorn + FastAPI 请求日志
|
|
43
|
+
- **前端日志**: webpack 构建和热重载日志
|
|
44
|
+
|
|
45
|
+
### 重启服务
|
|
46
|
+
在nodemon控制台输入 `rs` 可以手动重启后端服务。
|
|
47
|
+
|
|
48
|
+
### 常见问题
|
|
49
|
+
1. **端口占用**: 确保9080和3002端口没有被其他程序占用
|
|
50
|
+
2. **虚拟环境**: 确保`.venv`目录存在且包含正确的Python环境
|
|
51
|
+
3. **依赖安装**: 运行`npm install`确保所有依赖已安装
|
|
52
|
+
|
|
53
|
+
## 📁 项目结构
|
|
54
|
+
```
|
|
55
|
+
├── src/ # Python 后端源码
|
|
56
|
+
├── frontend/ # React 前端源码
|
|
57
|
+
├── config/ # 配置文件
|
|
58
|
+
├── nodemon.json # nodemon 配置
|
|
59
|
+
└── package.json # npm 脚本和依赖
|
|
60
|
+
```
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# 前端文件集成指南
|
|
2
|
+
|
|
3
|
+
GraphXR Database Proxy 支持将前端文件打包到 Python 包中,这样安装包后就能直接访问完整的 Web UI。
|
|
4
|
+
|
|
5
|
+
## 🏗️ 构建流程
|
|
6
|
+
|
|
7
|
+
### 1. 前端构建和打包
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 构建前端并复制到 Python 包
|
|
11
|
+
python scripts/build_frontend.py
|
|
12
|
+
|
|
13
|
+
# 构建完整包(包含前端)
|
|
14
|
+
python scripts/publish.py build
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. 自动化构建
|
|
18
|
+
|
|
19
|
+
发布脚本会自动处理前端构建:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# 发布到 TestPyPI(包含前端构建)
|
|
23
|
+
python scripts/publish.py test
|
|
24
|
+
|
|
25
|
+
# 发布到 PyPI(包含前端构建)
|
|
26
|
+
python scripts/publish.py prod
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 📁 文件结构
|
|
30
|
+
|
|
31
|
+
### 开发时
|
|
32
|
+
```
|
|
33
|
+
frontend/
|
|
34
|
+
├── src/ # 前端源码
|
|
35
|
+
├── dist/ # 前端构建输出
|
|
36
|
+
└── package.json
|
|
37
|
+
|
|
38
|
+
src/graphxr_database_proxy/
|
|
39
|
+
├── static/ # 复制的前端文件(构建时生成)
|
|
40
|
+
└── main.py # FastAPI 应用
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 发布后
|
|
44
|
+
```
|
|
45
|
+
graphxr_database_proxy/
|
|
46
|
+
├── static/ # 打包的前端文件
|
|
47
|
+
│ ├── index.html
|
|
48
|
+
│ ├── main.js
|
|
49
|
+
│ ├── vendors.js
|
|
50
|
+
│ └── ...
|
|
51
|
+
└── main.py
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 🚀 使用方式
|
|
55
|
+
|
|
56
|
+
### 作为包使用
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from graphxr_database_proxy import DatabaseProxy
|
|
60
|
+
from graphxr_database_proxy.main import app
|
|
61
|
+
|
|
62
|
+
# 创建代理
|
|
63
|
+
proxy = DatabaseProxy()
|
|
64
|
+
|
|
65
|
+
# 启动服务(包含 Web UI)
|
|
66
|
+
proxy.start()
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 命令行使用
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 安装包
|
|
73
|
+
pip install graphxr-database-proxy
|
|
74
|
+
|
|
75
|
+
# 启动服务(包含 Web UI)
|
|
76
|
+
graphxr-proxy --host 0.0.0.0 --port 9080
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
访问 http://localhost:9080 查看 Web UI。
|
|
80
|
+
|
|
81
|
+
## 🔧 静态文件服务
|
|
82
|
+
|
|
83
|
+
FastAPI 应用会自动检测静态文件位置:
|
|
84
|
+
|
|
85
|
+
1. **生产环境**: 使用包内的 `static/` 目录
|
|
86
|
+
2. **开发环境**: 使用 `frontend/dist/` 目录
|
|
87
|
+
3. **回退**: 显示提示信息
|
|
88
|
+
|
|
89
|
+
### 代码示例
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# main.py 中的静态文件配置
|
|
93
|
+
static_dir = Path(__file__).parent / "static"
|
|
94
|
+
frontend_dist = Path(__file__).parent.parent.parent / "frontend" / "dist"
|
|
95
|
+
|
|
96
|
+
# 优先使用打包的静态文件
|
|
97
|
+
if static_dir.exists() and any(static_dir.iterdir()):
|
|
98
|
+
app.mount("/static", StaticFiles(directory=str(static_dir)), name="static")
|
|
99
|
+
|
|
100
|
+
@app.get("/{full_path:path}")
|
|
101
|
+
async def serve_frontend(full_path: str):
|
|
102
|
+
index_file = static_dir / "index.html"
|
|
103
|
+
if index_file.exists():
|
|
104
|
+
return FileResponse(str(index_file))
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 🧪 测试验证
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 测试包的完整性(包括静态文件)
|
|
111
|
+
python scripts/test_package.py
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
测试会验证:
|
|
115
|
+
- ✅ 静态文件是否正确包含
|
|
116
|
+
- ✅ FastAPI 应用是否正常工作
|
|
117
|
+
- ✅ 路由是否正确配置
|
|
118
|
+
|
|
119
|
+
## 📦 包配置
|
|
120
|
+
|
|
121
|
+
### pyproject.toml
|
|
122
|
+
```toml
|
|
123
|
+
[tool.setuptools.package-data]
|
|
124
|
+
"graphxr_database_proxy" = ["static/*", "static/**/*"]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### MANIFEST.in
|
|
128
|
+
```
|
|
129
|
+
# 包含静态文件
|
|
130
|
+
recursive-include src/graphxr_database_proxy/static *
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## 🔄 开发工作流
|
|
134
|
+
|
|
135
|
+
1. **开发前端**
|
|
136
|
+
```bash
|
|
137
|
+
cd frontend
|
|
138
|
+
npm run dev # 开发模式
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
2. **构建前端**
|
|
142
|
+
```bash
|
|
143
|
+
python scripts/build_frontend.py
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
3. **测试完整包**
|
|
147
|
+
```bash
|
|
148
|
+
python scripts/publish.py build
|
|
149
|
+
python scripts/test_package.py
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
4. **发布**
|
|
153
|
+
```bash
|
|
154
|
+
python scripts/publish.py test # 测试发布
|
|
155
|
+
python scripts/publish.py prod # 正式发布
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 📝 注意事项
|
|
159
|
+
|
|
160
|
+
1. **文件大小**: 包含前端后,包大小会增加到约 1.7MB
|
|
161
|
+
2. **构建依赖**: 需要 Node.js 环境来构建前端
|
|
162
|
+
3. **版本同步**: 前端和后端版本需要保持同步
|
|
163
|
+
4. **缓存清理**: 构建前会自动清理旧的静态文件
|
|
164
|
+
|
|
165
|
+
## 🆘 故障排除
|
|
166
|
+
|
|
167
|
+
### 前端文件缺失
|
|
168
|
+
```bash
|
|
169
|
+
# 重新构建前端
|
|
170
|
+
python scripts/build_frontend.py
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### 包大小异常
|
|
174
|
+
```bash
|
|
175
|
+
# 检查包内容
|
|
176
|
+
python -m zipfile -l dist/graphxr_database_proxy-*.whl | grep static
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 静态文件访问失败
|
|
180
|
+
```bash
|
|
181
|
+
# 测试包完整性
|
|
182
|
+
python scripts/test_package.py
|
|
183
|
+
```
|