tiny-engine icon indicating copy to clipboard operation
tiny-engine copied to clipboard

feat: add API Proxy in dataSource, add some mock API, add some cases

Open 1degrees opened this issue 9 months ago • 1 comments

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our Commit Message Guidelines
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been added / updated (for bug fixes / features)
  • [x] Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Documentation content changes
  • [ ] Other... Please describe:

Background and solution

What is the current behavior?

具体功能可翻阅群聊聊天记录视频,视频太大无法上传。

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

Summary by CodeRabbit

  • New Features

    • Added support for configuring and using proxy settings in data sources, including UI for proxy management.
    • Introduced global lifecycle hooks for data fetching, processing, and error handling in data sources.
    • Enabled proxy-based API requests with new endpoints and mock data for testing.
    • Enhanced HTTP client and data source handling for more flexible request/response interceptors and proxy integration.
  • Bug Fixes

    • Corrected naming inconsistencies in global data handler functions.
  • Chores

    • Updated dependencies, including adding or upgrading Axios and http-proxy-middleware to improve compatibility and functionality.

1degrees avatar Mar 13 '25 13:03 1degrees

Walkthrough

This update introduces comprehensive support for proxy configuration and handling across the mock server, data source management, and code generation layers. It adds proxy settings at both the global and per-data-source levels, updates server routes to support proxying API requests, and modifies the HTTP client and data source loading logic to utilize these proxy settings. The UI components are enhanced to allow users to configure proxy settings. Supporting code, configuration files, and generated outputs are updated to ensure consistent proxy handling, improved error management, and more flexible data fetching workflows.

Changes

File(s) Change Summary
mockServer/src/assets/json/appinfo.json, mockServer/src/assets/json/sources.json, mockServer/src/mock/get/app-center/apps/detail/1.json, mockServer/src/mock/get/app-center/sources/list/1.json, mockServer/src/mock/get/app-center/v1/apps/schema/1.json Added a new data source entry "testProxyApi" with proxy, handler, and error handling functions. Introduced or updated global proxy configuration and handler functions in global data source configs.
mockServer/package.json, packages/design-core/package.json Added new dependencies: http-proxy-middleware and axios (updated version constraints).
mockServer/src/routes/main-routes.js Added POST route for updating global data source and a catch-all proxy route for /app-proxy/api/* using http-proxy-middleware.
mockServer/src/services/source.js Added update method to update global data source configuration in multiple JSON files.
mockServer/src/services/app.js Updated how dataSource is constructed to include new proxy and nested handler properties.
packages/build/vite-config/src/default-config.js Added /app-proxy/api proxy configuration for development server.
packages/design-core/src/preview/src/preview/Preview.vue Injected proxy info into global app context for preview, updated code handling.
packages/design-core/src/preview/src/preview/generate.js Added generateDataSource function to export data sources with handlers and proxy info.
packages/design-core/src/preview/src/preview/srcFiles.js, packages/design-core/src/preview/src/preview/srcFiles/http.js Added new HTTP client module supporting proxy and handler injection.
packages/design-core/src/preview/src/preview/srcFiles/dataSourceMap.js Refactored data source map to support dynamic function creation and proxy-aware loading.
packages/plugins/datasource/src/DataSourceGlobalDataHandler.vue UI: Added proxy configuration section and integrated proxy state management.
packages/plugins/datasource/src/RemoteDataAdapterForm.vue Enhanced prop types and options for code editor, supporting string/object values.
packages/plugins/datasource/src/js/datasource.ts Enhanced data source loader to handle proxy settings and return promises consistently.
packages/plugins/materials/src/composable/useResource.ts Integrated proxy config into resource fetching and state management.
packages/vue-generator/src/templates/vue-template/templateFiles/genViteConfig.js Updated Vite config generator to accept schema and inject proxy configuration.
packages/vue-generator/src/templates/vue-template/templateFiles/src/http/index.js Refactored HTTP client to accept multiple handlers for requests and responses.
packages/vue-generator/src/templates/vue-template/templateFiles/src/lowcodeConfig/dataSource.js Enhanced data source loader to support global/local handlers and consistent promise returns.
packages/vue-generator/test/testcases/element-plus-case/expected/appdemo01/package.json, packages/vue-generator/test/testcases/generator/expected/appdemo01/package.json Updated axios dependency version constraints.
packages/vue-generator/test/testcases/element-plus-case/expected/appdemo01/src/http/index.js, packages/vue-generator/test/testcases/generator/expected/appdemo01/src/http/index.js Refactored HTTP client to accept multiple handler functions.
packages/vue-generator/test/testcases/element-plus-case/expected/appdemo01/src/lowcodeConfig/dataSource.js, packages/vue-generator/test/testcases/generator/expected/appdemo01/src/lowcodeConfig/dataSource.js Refactored data source loader for handler and proxy support.
packages/vue-generator/test/testcases/generator/expected/appdemo01/src/lowcodeConfig/dataSource.json Added "testProxyApi" data source entry with proxy and handler functions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UI
    participant Preview
    participant HTTPClient
    participant MockServer
    participant ProxyTarget

    Client->>UI: Configure data source with proxy settings
    UI->>MockServer: POST /app-center/api/apps/update/:id (with proxy config)
    MockServer->>MockServer: Update global data source config
    UI->>Preview: Run app preview
    Preview->>HTTPClient: Request data (with proxy info)
    HTTPClient->>MockServer: /app-proxy/api/... (with proxy_app_id)
    MockServer->>ProxyTarget: Forward request via http-proxy-middleware
    ProxyTarget-->>MockServer: Respond with data
    MockServer-->>HTTPClient: Return proxied response
    HTTPClient-->>Preview: Process response with handlers
    Preview-->>UI: Display proxied data

Poem

In tunnels of proxy, the packets hop, Through rabbit holes, requests never stop. With handlers and configs, they bounce and they play, Bringing fresh data the low-code way. Now with a proxy, your APIs are free, Hopping through networks, as swift as can be! — 🐇✨

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 13 '25 13:03 coderabbitai[bot]