Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Docker Setup, Resolve CORS Issues, and Fix Dependency Conflicts #170

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

lcolok
Copy link
Contributor

@lcolok lcolok commented Aug 19, 2024

Optimize Docker Setup, Resolve CORS Issues, and Fix Dependency Conflicts

Key Changes

  1. Optimized the frontend Dockerfile for better caching and faster builds:

    • Separated package installation from source code copying
    • Added concise comments explaining the structure's benefits
  2. Implemented a development-mode solution for CORS issues:

    • Restructured frontend.dockerfile to use npm start (vite --host --mode dev)
    • Configured Vite dev server in the frontend container to proxy API requests
    • Updated vite.config.ts to handle /solve endpoint proxying, allowing direct communication between containers
  3. Fixed a dependency conflict in the backend:

    • Downgraded griffe to version 0.48.0 in backend.dockerfile
  4. Updated README to reflect these changes:

    • Added explanation of the current CORS handling in development
    • Noted limitations and future considerations for production environments

Detailed Description

The frontend Dockerfile restructuring now utilizes Vite's development mode, allowing the frontend container to communicate with the backend container directly through http://backend:8002. This approach, combined with Vite's proxy service, effectively resolves CORS issues in the development environment.

We would like to acknowledge that this CORS resolution method was implemented based on the guidance provided in the frontend documentation. The documentation's suggestion to use Vite's proxy configuration in vite.config.ts was instrumental in resolving the CORS issues.

The griffe version downgrade addresses the issue reported in #166. We appreciate the community's contribution in identifying this problem.

These changes aim to improve the development experience, build efficiency, and resolve compatibility issues while providing a robust solution for CORS issues in the development environment. Future work will focus on implementing a production-ready approach to handle cross-origin requests.


优化 Docker 配置、解决跨域问题并修复依赖冲突

主要变更

  1. 优化前端 Dockerfile 以提高缓存利用率和构建速度:

    • 将包安装与源代码复制分离
    • 添加简洁的注释说明结构的优势
  2. 为跨域问题实现了开发模式解决方案

    • 重构 frontend.dockerfile 以使用 npm start(vite --host --mode dev)
    • 在前端容器中配置 Vite 开发服务器以代理 API 请求
    • 更新 vite.config.ts 以处理 /solve 端点的代理,实现容器间的直接通信
  3. 修复后端的依赖冲突

    • backend.dockerfile 中将 griffe 降级到 0.48.0 版本
  4. 更新 README 以反映这些变更:

    • 添加了对当前开发环境中跨域处理的解释
    • 注明了生产环境的限制和未来考虑事项

详细描述

前端 Dockerfile 的重构现在利用 Vite 的开发模式,允许前端容器通过 http://backend:8002 直接与后端容器通信。这种方法结合 Vite 的代理服务,有效解决了开发环境中的跨域问题。

我们要特别感谢前端文档中提供的指导。文档中建议在 vite.config.ts 中使用 Vite 的代理配置的方法对解决跨域问题起到了关键作用。

griffe 版本的降级解决了 #166 中报告的问题。我们感谢社区在识别这个问题上的贡献。

这些改动旨在改善开发体验、提高构建效率并解决兼容性问题,同时为开发环境中的跨域问题提供了稳健的解决方案。未来的工作将集中在实现适用于生产环境的跨源请求处理方法。

@Harold-lkk Harold-lkk merged commit 4c053ec into InternLM:main Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants