前端需要了解后端最简单的启动服务器
使用node,先创建根目录文件夹heServe,然后npm init -y 初始化项目,然后安装服务端框架koa(可以采用express或者egg)即npm install koa-static
hrServe中新建public目录,并拷贝上打包的dist目标内容到hrServer/public
在根目录下创建app.js
const Koa = require('koa')
const serve = require('koa-static');
const app = new Koa();
app.use(serve(__dirname + "/public")); //将public下的代码静态化
app.listen(3333, () => {
console.log('人资项目启动: 3333端口')
})
2.history模式。需要一下配置
// 创建路由实例
const createRouter = () => new Router({
mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
// 指定路由规则
routes: [
...constantRoutes // 静态路由, 首页
]
})
3。npm install koa2-connect-history-api-fallback #专门处理history模式的中间件
在app.js中加入const { historyApiFallback } = require('koa2-connect-history-api-fallback');
4.安装跨域代理中间件
app.use(proxy({
targets: {
'/api/(.*)': {
target: 'http://ihrm-java.itheima.net', //后端服务器地
changeOrigin: true
}
}
}))
npm install koa2-proxy-middleware
在app.js中加上
app.use(historyApiFallback({
whiteList: ['/api']
}))
- 复制链接
- 举报