next.config.js 521 B

12345678910111213141516171819
  1. // next.config.js
  2. const { createProxyMiddleware } = require('http-proxy-middleware');
  3. module.exports = {
  4. devServer: {
  5. before(app) {
  6. app.use(
  7. '/api',
  8. createProxyMiddleware({
  9. target: 'http://your-backend-api.com', // 你的后端 API 地址
  10. changeOrigin: true,
  11. pathRewrite: {
  12. '^/api': '', // 重写路径
  13. },
  14. })
  15. );
  16. },
  17. },
  18. };