const path = require(‘path’); const webpack = require(‘webpack’) const { VueLoaderPlugin } = require(‘vue-loader’) const HtmlWebpackPlugin = require(‘html-webpack-plugin’); const config = require(‘…/…/webpack.app.config’) const bodyParser = require(‘body-parser’)
var proxyUrl = “http://127.0.0.1:8888”;
config.output.path = path.join(config.output.path,‘router’) // = { // // filename: ‘main.js’, // path: path.resolve(__dirname, ‘dist’), // } config.resolve.alias[‘@’]=path.resolve(__dirname, ‘src/’)
config.devServer= { static: ‘./dist’, // before:function(app,server){
// }, setupMiddlewares: function(middlewares, devServer) { if (!devServer) { throw new Error(‘webpack-dev-server is not defined’); } middlewares.unshift(bodyParser.json()); // app.use(bodyParser.json()) //通过bodyParser获取req.body
middlewares.push( (req, response) => {
console.log('===========devserver==============')
console.log(req.url)
response.send('setup-middlewares option GET');
});
return middlewares;
}, proxy: { “/OAapp”: { target: “http://v9.ht.oa8000.com.cn”, //API服务器的地址 changeOrigin: true },
"/vueim": {
target: "http://v9imserver.ht.oa8000.com.cn", //API服务器的地址
// target: "http://localhost:2000", //API服务器的地址
changeOrigin: true,
// secure:false,
pathRewrite: {
"^/vueim": "/OAapp",
},
onProxyReq: function (proxyReq, req, res) {
if (req.body) {
const reg = new RegExp('application/json')
if (reg.test(proxyReq.getHeader('Content-Type'))) {
const bodyData = JSON.stringify(req.body)
const headerNames=proxyReq.getRawHeaderNames()
// const auth = proxyReq.getHeader("authorization")
headerNames.map(name=>{
// console.log(33333333333,name,proxyReq.getHeader(name))
if(!['authorization','host','content-type'].includes(name))
proxyReq.removeHeader(name)
})
// proxyReq.setHeader("host","v9imserver.ht.oa8000.com.cn")
// proxyReq.setHeader("authorization",auth)
// proxyReq.setHeader("Connection","keep-alive")
// proxyReq.setHeader('Content-Type','application/json');
// proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
// console.log(111111111111111,req.url,bodyData)
// stream the content
proxyReq.write(Buffer.from(bodyData,'utf-8'))
proxyReq.end()
}
}
},
onProxyRes: function (proxyRes, req, res) {
if ("/OAapp/v1/user/login" == req.url) {
var body = [];
proxyRes.on("data", (d) => body.push(d));
proxyRes.on("end", function () {
console.log(222222222222, Buffer.concat(body))
});
} else {
console.log(2222222222,req.url);
}
},
},
"/OAapp-01": {
target: proxyUrl, //API服务器的地址
//ws: true, //代理websockets
changeOrigin: true, // 是否跨域,虚拟的站点需要更管origin
// pathRewrite: {
// '^/api5'是一个正则表达式,表示要匹配请求的url中,全部'http://localhost:8081/api5' 转接为 http://localhost:8081/api/
// "^/api5": "/api",
//重写路径 比如'/api/aaa/ccc'重写为'/aaa/ccc'
// "^/api": "",
// "^/OAapp/HtEntranceService.do": "",
// },
bypass: function (req, res, proxyOptions) {
// console.log(JSON.stringify(req.headers), proxyOptions);
// if (req.headers.accept.indexOf("html") !== -1) {
// console.log("Skipping proxy for browser request.");
// return "/index.html";
// }
},
onProxyReq: function (proxyReq, req, res) {
var body = [];
req.on("data", (d) => body.push(d));
req.on("end", function () {
req.body = Buffer.concat(body).toString();
// console.log("onProxyReq-----------------------\n", Buffer.concat(body).toString());
});
},
onProxyRes: function (proxyRes, req, res) {
if ("/OAapp/HtEntranceService.do" == req.url) {
var body = [];
proxyRes.on("data", (d) => body.push(d));
proxyRes.on("end", function () {
unzip(Buffer.concat(body), (err, buffer) => {
if (err) {
console.error("An error occurred:", err);
process.exitCode = 1;
}
body = buffer.toString();
console.log("onProxyRes----------------------------------------------\n", body);
console.log(req.url);
console.log(
"req body:\n",
req.body,
"\nres body:\n",
Base64ToolService.doDecode2(body.replace(/\\n|\\r/g, ""))
);
});
});
} else {
console.log(req.url);
}
},
onError(err, req, res, target) {
console.log("onError-----------------------");
console.log(err, res);
console.log("onError-----------------------");
},
},
"/htoa": {
target: proxyUrl, //API服务器的地址
changeOrigin: true, // 是否跨域,虚拟的站点需要更管origin
},
},
},
config.plugins.push( new HtmlWebpackPlugin({ template: ‘index.html’ }) // new HtmlWebpackPlugin({ // title: ‘vue-webpack’, // template: path.resolve(__dirname,‘public/index.html’), // templateParameters: { // ‘BASE_URL’: ‘/’ // } // }) ) module.exports = config // { // …config,
// output: { // filename: ‘main.js’, // path: path.resolve(__dirname, ‘dist’), // },
// resolve: { // alias: { // ‘@’: path.resolve(__dirname, ‘src/’), // } // }, // plugins: [ // // make sure to include the plugin! // new HtmlWebpackPlugin({ // title: ‘vue-webpack’, // template: path.resolve(__dirname,‘public/index.html’), // templateParameters: { // ‘BASE_URL’: ‘/’ // } // }), // ] // };
const path = require(‘path’); const webpack = require(‘webpack’) const { VueLoaderPlugin } = require(‘vue-loader’) const HtmlWebpackPlugin = require(‘html-webpack-plugin’);
console.log(__dirname directory: ${__dirname} ); console.log(Current directory: ${process.cwd()} );
module.exports = { mode: ‘development’, devtool: ‘source-map’, devServer: { static: ‘./dist’, }, // stats:‘verbose’, entry: ‘./src/main.js’, output: { filename: ‘[name].js’, path: path.resolve(__dirname, ‘dist’), clean: true }, resolve: { // 如果确认需要node polyfill,设置resolve.fallback安装对应的依赖 fallback: { crypto: require.resolve(‘crypto-browserify’), path: require.resolve(‘path-browserify’), url: require.resolve(‘url’), buffer: require.resolve(‘buffer/’), util: require.resolve(‘util/’), stream: require.resolve(‘stream-browserify/’), vm: require.resolve(‘vm-browserify’), “https”: require.resolve(“https-browserify”), “http”: require.resolve(“stream-http”), “zlib”: require.resolve(“browserify-zlib”) }, // 如果确认不需要node polyfill,设置resolve.alias设置为false alias: { crypto: false, fs: false, tls: false, net: false, ‘@’: path.resolve(process.cwd(), ‘src/’), }, extensions: [ ‘.mjs’, ‘.js’, ‘.jsx’, ‘.vue’, ‘.json’, ‘.wasm’ ], }, module: { rules: [ // … other rules { test: /.vueKaTeX parse error: Expected 'EOF', got '}' at position 39: …-loader' }?, // this…/, loader: ‘babel-loader’, exclude: file => ( /node_modules/.test(file) // && !/.vue.js/.test(file) ), options: { presets: [[‘@babel/preset-env’, { /** * 当我做polyfill填充的时候,去加一些低版本特性的时候,我不是把所有特性都加进来 * 是根据你的业务代码来决定要加什么 */ useBuiltIns: ‘entry’, corejs: 3 }]] } }, // this will apply to both plain `.css` files // AND `
|