Toc
0 results found
bbcfive
express的proxy实现前后端分离
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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.
})
本文作者:bbcfive
版权声明:本文首发于bbcfive的博客,转载请注明出处!