You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/guide/config-run.md
+19-2Lines changed: 19 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Run & Deploy
1
+
# Configure, Run & Deploy
2
2
3
3
This document describes how to configure and run the UtilMeta service and how to deploy it in a production environment.
4
4
@@ -24,6 +24,7 @@ The first parameter of the UtilMeta service receives the name of the current mod
24
24
*`asynchronous`: whether the service provides an asynchronous APIs. The default is determined by the runtime framework.
25
25
*`api`: pass in UtilMeta’s root API class or its reference string
26
26
*`route`: pass in the path string of the root API. The default is `'/'`, which will mount to the root path.
27
+
*`auto_reload`: set to `True` to enable service auto reload when the code changed during debug, default is None.
27
28
28
29
When you initialize UtilMeta, you can also import the UtilMeta service instance of the current process in this way
29
30
@@ -393,7 +394,23 @@ UtilMeta provides a `DjangoSettings` configuration that provides declarative Dja
393
394
394
395
*`secret_key`: Specifies the **secret key** for Django. It is recommended to generate a long random key in the environment variable.
395
396
*`apps`: for specifying Django `INSTALLED_APPS`.
396
-
*`apps_package`: This is a convenient configuration item. If your installed apps are all in a package, you can use `apps_package` to specify the path of the package. UtilMeta will read all the subfolders in it to find the Django app.
397
+
*`apps_package`: If your django apps are defined under some folder, such as:
398
+
```hl_lines="3"
399
+
/project
400
+
/config
401
+
/domain
402
+
/app1
403
+
/migrations
404
+
models.py
405
+
/app2
406
+
/migrations
407
+
models.py
408
+
```
409
+
410
+
You can specify `apps_package='domain'` to easily recognize all apps under the `/domain` folder, current approach is to detect all subfolders with `migrations` folder.
411
+
412
+
If the are multiple packages that contains apps, you can pass in a list like `apps_package=['domain.apps', 'vendors']`
413
+
397
414
*`middleware`: You can pass in a list of Django middleware here.
398
415
*`module_name`: Specifies the configuration file reference for Django.
399
416
*`extra`: You can pass in a dict to specify additional Django configuration.
Copy file name to clipboardExpand all lines: docs/en/guide/migration.md
+50-1Lines changed: 50 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -200,12 +200,61 @@ if __name__ == "__main__":
200
200
201
201
Just take the result of `API.__as__` as a route of `tornado.web.Application`
202
202
203
-
### Integration rules
203
+
### API Integration rules
204
204
205
205
When integrate UtilMeta to other existing projects, you should only integrate **One** API classes. If you develop other API classes, you can use API mounting as a subroute of the integrated API classes.
206
206
207
207
Because the service is not controlled by UtilMeta when the UtilMeta API integrate other projects, so `API.__as__` will create a hidden UtilMeta service for control, in order to avoid service conflicts, you can only call the `API.__as__` function once.
208
208
209
+
### Configure UtilMeta service
210
+
211
+
You can declare a UtilMeta service instance to inject your configurations. Set the API class you defined as root API of service using `api` param, then replace the `__as__` method to `service.adapt` to adapt the entire service, like:
212
+
213
+
```python hl_lines="34"
214
+
import django
215
+
from django.urls import re_path
216
+
from django.http.response import HttpResponse
217
+
from utilmeta.core import api, response
218
+
219
+
classTimeAPI(api.API):
220
+
classresponse(response.Response):
221
+
result_key ='data'
222
+
message_key ='msg'
223
+
224
+
@api.get
225
+
defnow(self):
226
+
returnself.request.time
227
+
228
+
defdjango_test(request, route: str):
229
+
return HttpResponse(route)
230
+
231
+
from utilmeta import UtilMeta
232
+
from utilmeta.conf import Time
233
+
234
+
service = UtilMeta(
235
+
__name__,
236
+
name='time',
237
+
backend=django,
238
+
api=TimeAPI,
239
+
)
240
+
service.use(Time(
241
+
datetime_format="%Y-%m-%d %H:%M:%S",
242
+
use_tz=False
243
+
))
244
+
245
+
urlpatterns = [
246
+
re_path('test/(.*)', django_test),
247
+
service.adapt('/api/v1/time')
248
+
]
249
+
```
250
+
`service.adapt` takes a route param to specify the adapted route that will prepend to the UtilMeta service root url. Using the above method, when request `/api/v1/time/now`, you will see the datetime string using the configured format:
251
+
```json
252
+
{"data": "2025-04-15 16:38:30", "msg": ""}
253
+
```
254
+
255
+
!!! note
256
+
The `backend` param of UtilMeta service instance should be consistent to the framework the project using.
257
+
209
258
## Integrate other frameworks
210
259
211
260
Your UtilMeta project can also integrate other framework's APIs
When you connecting local API directly, it is not possible to directly send **cookies** from the browser to API service (because the UtilMeta platform is cross domain with local service). Connecting to online public services will not have this problem because requests can be forwarded through the UtilMeta platform. In the future, UtilMeta platform will launch browser plugin and desktop client to solve the problem. Currently, you can use [UtilMeta's declarative web client](../client) to write debugging scripts and test cases for local APIs with cookies.
258
+
256
259
### Connect Public Service
257
260
258
261
Connecting to the API service deployed online with public network address requires you to register an account on the UtilMeta platform. Because the management of online services requires a stricter authorization and authentication mechanism, you need to create a project team on the UtilMeta platform first. When you enter an empty project team, You can see the connection prompt for the UtilMeta platform
0 commit comments