We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
2.2.13
windows 11
16.20.0
Microsoft Edge 115.0.1901.200
直接把文档里面关于proxy设置的代码复制到本地.dumirc.ts中: ` import { defineConfig } from 'dumi';
export default defineConfig(() => { return { outputPath: 'docs-dist', themeConfig: { name: 'decore-ui', nav: [ { title: '介绍', link: '/guide' }, { title: '组件', link: '/components/Foo' }, ], logo: '/images/logo.jpg', showLineNum: true, footer: Copyright © ${new Date().getFullYear()} <a href="xxxxx" target="_blank" rel="noopener noreferrer">xxxx</a>, }, apiParser: {}, resolve: { // 配置入口文件路径,API 解析将从这里开始 entryFile: './src/index.ts', }, clickToComponent: {}, codeSplitting: { jsStrategy: 'granularChunks', }, favicons: ['/images/logo.jpg'], proxy: { '/api': { 'target': 'http://jsonplaceholder.typicode.com/', 'changeOrigin': true, 'pathRewrite': { '^/api' : '' }, } } }; }); 然后启动,组件中: useEffect(() => { axios({ method: 'get', url: '/api/users', }).then((res) => { console.log(res); }); }, []); ` 直接404
Copyright © ${new Date().getFullYear()} <a href="xxxxx" target="_blank" rel="noopener noreferrer">xxxx</a>
然后启动,组件中:
正常返回接口请求的信息
直接报404
No response
The text was updated successfully, but these errors were encountered:
您遇到的问题看起来可能与设置代理有关,以及在运行npm run dev时遇到404错误(可能是HTTP 404 Not Found)。这可能是由于代理配置不正确或代理服务器无法正确转发请求引起的。
npm run dev
以下是一些建议来解决这个问题:
确保您的代理设置正确。您可以在项目的配置文件(通常是webpack配置文件或项目根目录下的.env文件)中设置代理。例如,在Vue.js项目中,可以在vue.config.js文件中设置代理:
.env
vue.config.js
module.exports = { devServer: { proxy: { '/api': { target: 'http://your-api-server', changeOrigin: true, pathRewrite: { '^/api': '' } } } } };
请根据您的项目和服务器配置进行相应调整。
确保您的代理服务器正在运行,并且没有任何问题。您可以尝试直接访问代理服务器的地址,看看是否可以成功连接。
确保target字段指向正确的API服务器地址。如果您的API服务器地址是http://localhost:3000,那么target应该设置为这个地址。
target
http://localhost:3000
检查浏览器开发者工具(通常按下F12键并切换到Network选项卡)中关于404错误的详细信息。这可能会提供有关为何请求未找到的更多信息。
F12
在代理配置中,pathRewrite字段用于重写请求路径。确保它正确配置,以便正确映射到您的API路径。
pathRewrite
有时候,依赖关系可能有问题,您可以尝试重新安装依赖并重新启动项目:
npm install npm run dev
确保您的API服务器正在运行,并且端口号等配置正确。如果API服务器无法正常工作,前端项目将无法正确访问接口。
通过检查这些方面,您可能能够解决这个问题。如果问题仍然存在,请提供更多关于项目结构、代理配置和错误详细信息的信息,以便我可以提供更具体的帮助。
Sorry, something went wrong.
No branches or pull requests
Version
2.2.13
OS Version
windows 11
Node.js Version
16.20.0
Browser Version
Microsoft Edge 115.0.1901.200
Link to minimal reproduction
Steps to reproduce
直接把文档里面关于proxy设置的代码复制到本地.dumirc.ts中:
`
import { defineConfig } from 'dumi';
export default defineConfig(() => {
return {
outputPath: 'docs-dist',
themeConfig: {
name: 'decore-ui',
nav: [
{ title: '介绍', link: '/guide' },
{ title: '组件', link: '/components/Foo' },
],
logo: '/images/logo.jpg',
showLineNum: true,
footer:
Copyright © ${new Date().getFullYear()} <a href="xxxxx" target="_blank" rel="noopener noreferrer">xxxx</a>
,},
apiParser: {},
resolve: {
// 配置入口文件路径,API 解析将从这里开始
entryFile: './src/index.ts',
},
clickToComponent: {},
codeSplitting: {
jsStrategy: 'granularChunks',
},
favicons: ['/images/logo.jpg'],
proxy: {
'/api': {
'target': 'http://jsonplaceholder.typicode.com/',
'changeOrigin': true,
'pathRewrite': { '^/api' : '' },
}
}
};
});
然后启动,组件中:
useEffect(() => {
axios({
method: 'get',
url: '/api/users',
}).then((res) => {
console.log(res);
});
}, []);
`
直接404
What is expected?
正常返回接口请求的信息
What is actually happening?
直接报404
Any additional comments? (optional)
No response
The text was updated successfully, but these errors were encountered: