0
点赞
收藏
分享

微信扫一扫

【文末送书】全栈开发流程——后端连接数据源(二)

中间件小哥 2023-09-08 阅读 8

在config index.js文件中
在这里插入图片描述

引入如下代码即可


const path = require('path')
const devEnv = require('./dev.env')
module.exports = {
    dev: {

        // Paths
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: devEnv.OPEN_PROXY === false ? {} : {
            '/api': {
                target: 'http://localhost:8083',
                changeOrigin: true,
                pathRewrite: {
                    '^/api': '/'
                }
            }
        },
// Paths
        assetsSubDirectory: 'static',
        assetsPublicPath: '/',
        proxyTable: devEnv.OPEN_PROXY === false ? {} : {
            '/api': {
                target: 'http://localhost:8083', //需要更改的后端的端口号
                changeOrigin: true,
                pathRewrite: {
                    '^/api': '/'
                }
            }
        },
        这里的配置是正则表达式,以/api开头的将会被用用‘/api'替换掉,假如后台文档的接口是 /api/list/xxx

//前端api接口写:axios.get('/api/list/xxx') , 被处理之后实际访问的是:http://news.baidu.com/api/list/xxx

}

}},

 

 
举报

相关推荐

0 条评论