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

前端调用后端服务的地址127.0.0.1 ,如何修改 #17

Open
gjfmlj opened this issue Feb 11, 2025 · 7 comments
Open

前端调用后端服务的地址127.0.0.1 ,如何修改 #17

gjfmlj opened this issue Feb 11, 2025 · 7 comments

Comments

@gjfmlj
Copy link

gjfmlj commented Feb 11, 2025

改了前端和后端服务允许0.0.0.0访问
并且修改 frontend/src/utils/request.ts 这个文件中的baseUrl

用户访问后有报错
INFO: 10.10.31.61:51436 - "GET /api/llm/providers HTTP/1.1" 200 OK
INFO: 10.10.31.61:51437 - "OPTIONS /api/voice/voices HTTP/1.1" 400 Bad Request

不知还有哪里需要修改?

@alecm20
Copy link
Owner

alecm20 commented Feb 11, 2025

你是什么修改的?把你的改动贴出来?

@gjfmlj
Copy link
Author

gjfmlj commented Feb 11, 2025

本地127启动使用正常使用
改成内网的ip启动前后端
uvicorn main:app --host 0.0.0.0 --reload --port 8000
npm run dev -- --host 0.0.0.0

修改story-flicks/frontend/src/utils/request.ts内容如下:

import axios from 'axios';

interface RequestConfig {
url: string;
method: string;
data?: object;
headers?: object;
params?: object;
}

let baseUrl = 'http://192.168.1.10:8000';

export function request(config: RequestConfig): Promise {
return new Promise((resolve, reject) => {
axios.request({
...config,
baseURL: baseUrl
}).then((response) => {
resolve(response.data);
}).catch((error) => {
reject(error);
});
});

}

@alecm20
Copy link
Owner

alecm20 commented Feb 11, 2025

用这个方式启动后端,uvicorn main:app --host 0.0.0.0 --port 8000 --reload
然后在 backend/main.py 中添加跨域的 url, allow_origins=["http://localhost:5173", "http://127.0.0.1:5173", "http://192.168.1.10:5173"], 试一下

@gjfmlj
Copy link
Author

gjfmlj commented Feb 11, 2025

页面加载成功了,但是生成视频后,页面上没有正确显示完成的视频,
链接到了
http://127.0.0.1:8000/tasks/1739255261/video.mp4

@alecm20
Copy link
Owner

alecm20 commented Feb 12, 2025

页面加载成功了,但是生成视频后,页面上没有正确显示完成的视频, 链接到了 http://127.0.0.1:8000/tasks/1739255261/video.mp4

这个你先手动处理下吧,backend/app/api/video.py的代码写了这个路径。

@gjfmlj
Copy link
Author

gjfmlj commented Feb 12, 2025

已可以正常工作,感谢指导。

另外提个建议,前台用户界面最好能默认填好各个参数,方便用户实用。

@alecm20
Copy link
Owner

alecm20 commented Feb 13, 2025

已可以正常工作,感谢指导。

另外提个建议,前台用户界面最好能默认填好各个参数,方便用户实用。

好的,这个我记一下

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

No branches or pull requests

2 participants