forked from vusion-templates/cloud-admin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.dev-server.js
61 lines (59 loc) · 2.18 KB
/
webpack.dev-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const host = 'localhost';
const path = require('path');
const pkg = require('./package.json');
const platformConfig = require('./platform.config.json');
if (!platformConfig.tenantId || !platformConfig.projectId) {
console.error('parse platform.config error');
process.exit(1);
}
const onProxyReq = function (proxyReq, req, res) {
proxyReq.removeHeader('x-forwarded-proto');
proxyReq.removeHeader('x-forwarded-host');
proxyReq.removeHeader('x-forwarded-port');
proxyReq.removeHeader('x-forwarded-for');
const cookies = {};
let cookie = proxyReq.getHeader('cookie');
cookie = typeof cookie === 'string' ? cookie.split('; ') : cookie;
if (Array.isArray(cookie)) {
cookie.forEach((item) => {
const arr = item.split('=');
if (arr.length === 2)
cookies[arr[0].toLowerCase()] = arr[1].trim();
});
}
cookies.authorization && proxyReq.setHeader('authorization', cookies.authorization);
cookies.username && proxyReq.setHeader('username', cookies.username);
proxyReq.setHeader('DomainName', pkg.name.replace(/-client$/, ''));
// console.log(proxyReq.path, proxyReq.getHeaders());
};
module.exports = function (port) {
return {
host,
port,
progress: !process.env.SERVER_DEVELOP,
open: true,
disableHostCheck: true,
contentBase: path.join(__dirname),
watchContentBase: false, // dev slow on Windows
clientLogLevel: 'info',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
proxy: {
'^/gateway/': {
target: 'http://api.gateway.lowcode',
changeOrigin: true,
autoRewrite: true,
onProxyReq,
},
'^/gw/': {
target: `http://${platformConfig.tenantId}-${platformConfig.projectId}.gateway.lowcode`,
changeOrigin: true,
autoRewrite: true,
onProxyReq,
},
},
};
};