-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathsetupProxy.js
46 lines (42 loc) · 1.54 KB
/
setupProxy.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
import fs from 'fs';
import path from 'path';
const vendorJsonPath = path.resolve(__dirname, './vendor.json');
let proxy = {};
if (fs.existsSync(vendorJsonPath)) {
proxy = JSON.parse(fs.readFileSync(vendorJsonPath, 'utf-8'));
}
const enableLiveEnviroment = {
css: false,
images: false,
locales: false
};
const domain = (proxy && proxy.url) || '';
const vendorCode = (proxy && proxy.code) || '';
export const proxyConfiguration = {
'/vendor-css': {
target: enableLiveEnviroment.css ? domain : 'http://localhost:5001',
changeOrigin: true,
rewrite: (path) => (enableLiveEnviroment.css ? path : path.replace(/^\/vendor-css\/css/, `/css/${vendorCode}`)),
},
'/public/html/app': {
target: domain,
changeOrigin: true,
rewrite: (path) => path,
headers: { 'Vendor-Code': vendorCode },
},
'/public/html/images': {
target: enableLiveEnviroment.images ? domain : 'http://localhost:5000',
changeOrigin: true,
rewrite: (path) => (enableLiveEnviroment.images ? path : path.replace(/^\/public\/html\/images/, `/public/html/${vendorCode}/vendor-images/images`)),
},
'/json': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: false,
},
'/locales': {
target: enableLiveEnviroment.locales ? domain : 'http://localhost:5000',
changeOrigin: true,
rewrite: (path) => (enableLiveEnviroment.locales ? path : path.replace(/^\/locales/, `/vendor-translation/processed/locales/${vendorCode}`)),
}
};