express的proxy实现前后端分离

var express = require('express')
var proxy = require('http-proxy-middleware')
var app = express()

app.use('/api', proxy({
   target: 'http://xxxxx', // 目标代理地址
   changeOrigin: true,
   pathRewrite: {
       '^/api': ''
   }  
}))

app.use(express.static('dist'))

app.get('*', function(req, res) {
    res.sendfile('./dist/index.html')
}) 

app.listen(8080, function(){
   do sth. 
})

 

posted @ 2019-01-13 17:28  执白  阅读(1091)  评论(0编辑  收藏  举报