一、搭建web服务器
const express=require('express')
const app=express()
const port=5000
app.use(express.static('public'))
app.listen(port,function(){
console.log(`> Open your browser width http://localhost:5000`)
})
二、可配置history模式
app.use(history()) //路由是否要配置history模式
三、可配置代理服务器
const {createProxyMiddleware}=require('http-proxy-middleware')
app.use('/api',createProxyMiddleware({
target:'http://10.50.12.213:80',//要代理的服务器
//secure:false,//如果是https接口,需要配置这个参数为true
changeOrign:true,
pathRewrite:{
'^/api':''
}
}))
四、完整代码如下
const {createProxyMiddleware}=require('http-proxy-middleware')
const express=require('express')
const app=express()
const port=5000
app.use(history())
app.use('/api',createProxyMiddleware({
target:'http://10.50.12.213:80',//要代理的服务器
//secure:false,//如果是https接口,需要配置这个参数为true
changeOrign:true,
pathRewrite:{
'^/api':''
}
}))
app.use(express.static('public'))
app.listen(port,function(){
console.log(`> Open your browser width http://localhost:5000`)
})