nextJS debug - 前端头像不显示
描述
前端主页头像加载不到资源(从后台的上传这里获取的url)
一开始以为是跨域问题没多管,配置nginx后发现问题还在
f12查看:"url" parameter is not allowed
检索相关信息之后发现是nextjs配置问题 (问gpt全错啊)
- https://www.kelen.cc/faq/nextjs-url-parameter-not-allowed
- https://stackoverflow.com/questions/67675288/next-js-image-component-error-url-parameter-is-valid-but-upstream-response-is
对应项目的 server.js
中 nextConfig
(原next.js的 next.config.js打包后挺隐蔽的)
解决
因为域名是用 HTTP
,该参数为接受xxx域名的数据
https://nextjscn.org/docs/app/api-reference/components/image#remotepatterns 对应value修改为 👇 ```json
"remotePatterns": [ { "protocol": "https", "hostname": "" }, { "protocol": "http", //添加一项 "hostname": "" } ], ```