@rancher/shell 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/styles/app.scss +1 -1
- package/assets/styles/fonts/_fontstack.scss +11 -11
- package/assets/styles/vendor/vue-js-modal.scss +3 -3
- package/assets/translations/en-us.yaml +92 -22
- package/assets/translations/zh-hans.yaml +84 -15
- package/babel.config.js +13 -0
- package/chart/gatekeeper.vue +77 -0
- package/chart/istio.vue +108 -111
- package/chart/logging/index.vue +13 -4
- package/chart/monitoring/index.vue +15 -5
- package/chart/monitoring/steps/uninstall-v1.vue +2 -2
- package/chart/rancher-backup/index.vue +10 -3
- package/cloud-credential/aws.vue +1 -1
- package/cloud-credential/digitalocean.vue +1 -1
- package/cloud-credential/gcp.vue +1 -1
- package/cloud-credential/generic.vue +2 -2
- package/cloud-credential/linode.vue +1 -1
- package/cloud-credential/pnap.vue +1 -1
- package/components/ActionMenu.vue +3 -4
- package/components/AssignTo.vue +1 -1
- package/components/AsyncButton.vue +1 -1
- package/components/BannerGraphic.vue +1 -1
- package/components/ButtonDropdown.vue +2 -3
- package/components/ChartPsp.vue +76 -0
- package/components/CruResource.vue +6 -2
- package/components/DashboardMetrics.vue +12 -10
- package/components/DetailText.vue +1 -1
- package/components/DisableAuthProviderModal.vue +1 -1
- package/components/EmberPage.vue +1 -1
- package/components/EtcdInfoBanner.vue +5 -4
- package/components/ExplorerMembers.vue +1 -1
- package/components/ExplorerProjectsNamespaces.vue +14 -1
- package/components/FileDiff.vue +6 -7
- package/components/GrafanaDashboard.vue +18 -21
- package/components/LazyImage.vue +10 -12
- package/components/LogItem.vue +1 -1
- package/components/Markdown.vue +1 -1
- package/components/PromptRemove.vue +2 -2
- package/components/PromptRestore.vue +1 -1
- package/components/ResourceDetail/Masthead.vue +16 -0
- package/components/ResourceDetail/index.vue +21 -4
- package/components/ResourceList/index.vue +1 -1
- package/components/ResourceTable.vue +4 -1
- package/components/SingleClusterInfo.vue +2 -2
- package/components/SortableTable/THead.vue +1 -1
- package/components/SortableTable/index.vue +5 -2
- package/components/__tests__/AsyncButton.test.ts +3 -1
- package/components/__tests__/ChartPsp.test.ts +75 -0
- package/components/__tests__/CruResource.test.ts +3 -1
- package/components/auth/Principal.vue +1 -1
- package/components/fleet/FleetBundles.vue +3 -1
- package/components/fleet/FleetClusters.vue +1 -2
- package/components/fleet/FleetIntro.vue +9 -1
- package/components/fleet/FleetNoWorkspaces.vue +62 -0
- package/components/fleet/FleetSummary.vue +7 -1
- package/components/form/LabeledSelect.vue +14 -11
- package/components/form/MatchExpressions.vue +17 -2
- package/components/form/NameNsDescription.vue +31 -45
- package/components/form/ResourceSelector.vue +1 -1
- package/components/form/SecretSelector.vue +5 -1
- package/components/form/ServiceNameSelect.vue +1 -1
- package/components/form/SimpleSecretSelector.vue +9 -9
- package/components/form/__tests__/LabeledSelect.test.ts +138 -0
- package/components/form/__tests__/NameNsDescription.ts +32 -0
- package/components/formatter/InternalExternalIP.vue +6 -0
- package/components/formatter/InvolvedObjectLink.vue +54 -0
- package/components/formatter/Link.vue +20 -4
- package/components/formatter/LinkName.vue +6 -1
- package/components/formatter/ServiceTargets.vue +1 -1
- package/components/nav/Group.vue +2 -2
- package/components/nav/NamespaceFilter.vue +15 -11
- package/components/nav/TopLevelMenu.vue +2 -4
- package/components/nav/Type.vue +1 -1
- package/components/nav/WorkspaceSwitcher.vue +46 -5
- package/config/labels-annotations.js +17 -0
- package/config/product/auth.js +3 -2
- package/config/product/explorer.js +11 -4
- package/config/product/fleet.js +2 -0
- package/config/router.js +414 -0
- package/config/table-headers.js +10 -2
- package/config/types.js +11 -8
- package/config/uiplugins.js +30 -0
- package/content/docs/en-us/whats-new.md +10 -0
- package/content/docs/zh-hans/whats-new.md +11 -1
- package/core/plugin-routes.ts +23 -0
- package/creators/app/app.package.json +2 -1
- package/creators/app/files/.eslintrc.js +1 -1
- package/creators/app/files/babel.config.js +1 -18
- package/creators/app/files/vue.config.js +7 -0
- package/creators/app/init +5 -5
- package/creators/pkg/files/.github/workflows/build-extension.yml +111 -0
- package/creators/pkg/init +35 -4
- package/creators/update/init +1 -1
- package/detail/constraints.gatekeeper.sh.constraint.vue +20 -10
- package/detail/fleet.cattle.io.gitrepo.vue +19 -11
- package/detail/harvesterhci.io.management.cluster.vue +3 -3
- package/detail/provisioning.cattle.io.cluster.vue +54 -12
- package/detail/workload/index.vue +3 -3
- package/dialog/AddClusterMemberDialog.vue +1 -1
- package/dialog/AddProjectMemberDialog.vue +2 -2
- package/dialog/AddonConfigConfirmationDialog.vue +27 -15
- package/dialog/DiagnosticTimingsDialog.vue +1 -1
- package/dialog/ForceMachineRemoveDialog.vue +1 -1
- package/dialog/GenericPrompt.vue +18 -6
- package/dialog/RotateEncryptionKeyDialog.vue +1 -1
- package/dialog/SaveAsRKETemplateDialog.vue +1 -1
- package/dialog/ScaleMachineDownDialog.vue +1 -1
- package/edit/auth/github.vue +8 -8
- package/edit/auth/googleoauth.vue +5 -5
- package/edit/auth/ldap/index.vue +1 -1
- package/edit/auth/oidc.vue +1 -1
- package/edit/auth/saml.vue +1 -1
- package/edit/cis.cattle.io.clusterscan.vue +1 -1
- package/edit/fleet.cattle.io.clustergroup.vue +6 -4
- package/edit/fleet.cattle.io.gitrepo.vue +16 -3
- package/edit/helm.cattle.io.projecthelmchart.vue +5 -1
- package/edit/management.cattle.io.fleetworkspace.vue +141 -6
- package/edit/management.cattle.io.podsecurityadmissionconfigurationtemplate.vue +4 -1
- package/edit/management.cattle.io.setting.vue +1 -1
- package/edit/monitoring.coreos.com.alertmanagerconfig/types/webhook.vue +2 -2
- package/edit/monitoring.coreos.com.receiver/tls.vue +18 -18
- package/edit/monitoring.coreos.com.receiver/types/webhook.banner.vue +4 -4
- package/edit/monitoring.coreos.com.receiver/types/webhook.vue +1 -1
- package/edit/namespace.vue +2 -2
- package/edit/networking.k8s.io.networkpolicy/PolicyRuleTarget.vue +126 -45
- package/edit/networking.k8s.io.networkpolicy/index.vue +1 -1
- package/edit/provisioning.cattle.io.cluster/MachinePool.vue +10 -0
- package/edit/provisioning.cattle.io.cluster/RegistryConfigs.vue +1 -0
- package/edit/provisioning.cattle.io.cluster/__tests__/rke2.test.ts +202 -2
- package/edit/provisioning.cattle.io.cluster/rke2.vue +248 -84
- package/edit/resources.cattle.io.backup.vue +1 -1
- package/edit/service.vue +1 -1
- package/edit/storage.k8s.io.storageclass/provisioners/driver.harvesterhci.io.vue +2 -2
- package/edit/workload/__tests__/Job.test.ts +3 -1
- package/edit/workload/index.vue +8 -3
- package/edit/workload/mixins/workload.js +16 -0
- package/layouts/default.vue +7 -3
- package/list/fleet.cattle.io.bundle.vue +6 -3
- package/list/fleet.cattle.io.clusterregistrationtoken.vue +3 -1
- package/list/fleet.cattle.io.gitrepo.vue +44 -5
- package/list/management.cattle.io.fleetworkspace.vue +45 -0
- package/list/node.vue +69 -16
- package/list/provisioning.cattle.io.cluster.vue +30 -1
- package/machine-config/azure.vue +97 -38
- package/middleware/authenticated.js +34 -0
- package/mixins/chart.js +73 -2
- package/mixins/resource-fetch.js +2 -2
- package/models/apps.statefulset.js +28 -0
- package/models/cluster/node.js +23 -2
- package/models/cluster.x-k8s.io.machine.js +4 -2
- package/models/clusterroletemplatebinding.js +7 -0
- package/models/constraints.gatekeeper.sh.constraint.js +9 -0
- package/models/fleet.cattle.io.cluster.js +19 -10
- package/models/fleet.cattle.io.gitrepo.js +7 -2
- package/models/management.cattle.io.cluster.js +1 -1
- package/models/management.cattle.io.fleetworkspace.js +12 -0
- package/models/management.cattle.io.gitreporestriction.js +5 -0
- package/models/management.cattle.io.podsecurityadmissionconfigurationtemplate.js +3 -0
- package/models/provisioning.cattle.io.cluster.js +7 -5
- package/nuxt/App.js +210 -0
- package/nuxt/axios.js +186 -0
- package/nuxt/client.js +817 -0
- package/nuxt/components/nuxt-build-indicator.vue +143 -0
- package/nuxt/components/nuxt-child.js +122 -0
- package/nuxt/components/nuxt-error.vue +98 -0
- package/nuxt/components/nuxt-link.client.js +98 -0
- package/nuxt/components/nuxt-link.server.js +16 -0
- package/nuxt/components/nuxt-loading.vue +154 -0
- package/nuxt/components/nuxt.js +101 -0
- package/nuxt/cookie-universal-nuxt.js +9 -0
- package/nuxt/empty.js +1 -0
- package/nuxt/index.js +365 -0
- package/nuxt/jsonp.js +82 -0
- package/nuxt/loading.html +39 -0
- package/nuxt/middleware.js +12 -0
- package/nuxt/mixins/fetch.client.js +90 -0
- package/nuxt/mixins/fetch.server.js +69 -0
- package/nuxt/portal-vue.js +4 -0
- package/nuxt/server.js +312 -0
- package/nuxt/store.js +178 -0
- package/nuxt/utils.js +630 -0
- package/nuxt/views/app.template.html +9 -0
- package/nuxt/views/error.html +23 -0
- package/package.json +5 -9
- package/pages/auth/setup.vue +2 -2
- package/pages/c/_cluster/apps/charts/__tests__/install.helper.test.ts +33 -0
- package/pages/c/_cluster/apps/charts/chart.vue +4 -4
- package/pages/c/_cluster/apps/charts/install.helpers.js +26 -0
- package/pages/c/_cluster/apps/charts/install.vue +40 -66
- package/pages/c/_cluster/explorer/EventsTable.vue +5 -19
- package/pages/c/_cluster/explorer/index.vue +29 -25
- package/pages/c/_cluster/explorer/tools/index.vue +8 -8
- package/pages/c/_cluster/fleet/index.vue +95 -34
- package/pages/c/_cluster/gatekeeper/index.vue +1 -1
- package/pages/c/_cluster/istio/index.vue +5 -5
- package/pages/c/_cluster/manager/cloudCredential/index.vue +1 -1
- package/pages/c/_cluster/monitoring/index.vue +7 -0
- package/pages/c/_cluster/uiplugins/InstallDialog.vue +8 -8
- package/pages/c/_cluster/uiplugins/PluginInfoPanel.vue +20 -7
- package/pages/c/_cluster/uiplugins/index.vue +49 -17
- package/pages/home.vue +9 -4
- package/pages/index.vue +10 -1
- package/plugins/clean-html-directive.js +31 -0
- package/plugins/dashboard-store/actions.js +32 -9
- package/plugins/dashboard-store/mutations.js +5 -2
- package/plugins/dashboard-store/resource-class.js +8 -1
- package/plugins/steve/mutations.js +3 -2
- package/plugins/steve/steve-description-class.js +5 -1
- package/plugins/steve/subscribe.js +63 -54
- package/plugins/steve-create-worker.js +14 -0
- package/promptRemove/management.cattle.io.globalrole.vue +2 -2
- package/promptRemove/management.cattle.io.project.vue +2 -2
- package/promptRemove/management.cattle.io.roletemplate.vue +2 -2
- package/promptRemove/pod.vue +1 -1
- package/public/index.html +65 -0
- package/rancher-components/components/Banner/Banner.test.ts +9 -1
- package/rancher-components/components/Banner/Banner.vue +1 -1
- package/rancher-components/components/Form/Checkbox/Checkbox.vue +2 -0
- package/rancher-components/components/Form/Radio/RadioButton.vue +1 -1
- package/scripts/build-pkg.sh +1 -0
- package/scripts/clean +6 -0
- package/scripts/extension/bundle +58 -0
- package/scripts/extension/helmpatch +89 -0
- package/scripts/extension/publish +314 -0
- package/scripts/test-plugins-build.sh +4 -0
- package/store/__tests__/index.test.ts +110 -0
- package/store/index.js +145 -58
- package/store/type-map.js +5 -1
- package/tsconfig.default.json +36 -0
- package/tsconfig.json +24 -0
- package/types/shell/index.d.ts +420 -343
- package/utils/__tests__/string.test.ts +12 -0
- package/utils/auth.js +65 -0
- package/utils/monitoring.js +2 -1
- package/utils/position.js +5 -8
- package/utils/router.scrollBehavior.js +80 -0
- package/utils/select.js +1 -3
- package/utils/socket.js +1 -0
- package/utils/string.js +13 -0
- package/utils/time.js +9 -0
- package/vue.config.js +679 -0
- package/chart/rancher-alerting-drivers.vue +0 -53
- package/chart/rancher-gatekeeper.vue +0 -37
- package/creators/app/files/nuxt.config.js +0 -6
- package/models/management.cattle.io.podsecurityadmissionconfigurationtemplate.ts +0 -4
- package/nuxt.config.js +0 -798
package/vue.config.js
ADDED
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const serveStatic = require('serve-static');
|
|
4
|
+
const webpack = require('webpack');
|
|
5
|
+
const { generateDynamicTypeImport } = require('./pkg/auto-import');
|
|
6
|
+
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
7
|
+
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
8
|
+
|
|
9
|
+
// This is currently hardcoded to avoid importing the TS
|
|
10
|
+
// const { STANDARD } = require('./config/private-label');
|
|
11
|
+
const STANDARD = 1;
|
|
12
|
+
|
|
13
|
+
const dev = (process.env.NODE_ENV !== 'production');
|
|
14
|
+
const devPorts = dev || process.env.DEV_PORTS === 'true';
|
|
15
|
+
|
|
16
|
+
// human readable version used on rancher dashboard about page
|
|
17
|
+
const dashboardVersion = process.env.DASHBOARD_VERSION;
|
|
18
|
+
|
|
19
|
+
const prime = process.env.PRIME;
|
|
20
|
+
|
|
21
|
+
const pl = process.env.PL || STANDARD;
|
|
22
|
+
const commit = process.env.COMMIT || 'head';
|
|
23
|
+
const perfTest = (process.env.PERF_TEST === 'true'); // Enable performance testing when in dev
|
|
24
|
+
const instrumentCode = (process.env.TEST_INSTRUMENT === 'true'); // Instrument code for code coverage in e2e tests
|
|
25
|
+
|
|
26
|
+
let api = process.env.API || 'http://localhost:8989';
|
|
27
|
+
|
|
28
|
+
if ( !api.startsWith('http') ) {
|
|
29
|
+
api = `https://${ api }`;
|
|
30
|
+
}
|
|
31
|
+
// ===============================================================================================
|
|
32
|
+
// Nuxt configuration
|
|
33
|
+
// ===============================================================================================
|
|
34
|
+
|
|
35
|
+
// Expose a function that can be used by an app to provide a nuxt configuration for building an application
|
|
36
|
+
// This takes the directory of the application as tehfirst argument so that we can derive folder locations
|
|
37
|
+
// from it, rather than from the location of this file
|
|
38
|
+
module.exports = function(dir, _appConfig) {
|
|
39
|
+
// Paths to the shell folder when it is included as a node dependency
|
|
40
|
+
let SHELL = 'node_modules/@rancher/shell';
|
|
41
|
+
let SHELL_ABS = path.join(dir, 'node_modules/@rancher/shell');
|
|
42
|
+
let COMPONENTS_DIR = path.join(SHELL_ABS, 'rancher-components');
|
|
43
|
+
|
|
44
|
+
if (fs.existsSync(SHELL_ABS)) {
|
|
45
|
+
const stat = fs.lstatSync(SHELL_ABS);
|
|
46
|
+
|
|
47
|
+
// If @rancher/shell is a symlink, then use the components folder for it
|
|
48
|
+
if (stat.isSymbolicLink()) {
|
|
49
|
+
const REAL_SHELL_ABS = fs.realpathSync(SHELL_ABS); // In case the shell is being linked via 'yarn link'
|
|
50
|
+
|
|
51
|
+
COMPONENTS_DIR = path.join(REAL_SHELL_ABS, '..', 'pkg', 'rancher-components', 'src', 'components');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// If we have a local folder named 'shell' then use that rather than the one in node_modules
|
|
56
|
+
// This will be the case in the main dashboard repository.
|
|
57
|
+
if (fs.existsSync(path.join(dir, 'shell'))) {
|
|
58
|
+
SHELL = './shell';
|
|
59
|
+
SHELL_ABS = path.join(dir, 'shell');
|
|
60
|
+
COMPONENTS_DIR = path.join(dir, 'pkg', 'rancher-components', 'src', 'components');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const babelPlugins = [
|
|
64
|
+
// TODO: Browser support
|
|
65
|
+
// ['@babel/plugin-transform-modules-commonjs'],
|
|
66
|
+
['@babel/plugin-proposal-private-property-in-object', { loose: true }]
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
if (instrumentCode) {
|
|
70
|
+
babelPlugins.push('babel-plugin-istanbul');
|
|
71
|
+
|
|
72
|
+
console.warn('Instrumenting code for coverage'); // eslint-disable-line no-console
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ===============================================================================================
|
|
76
|
+
// Functions for the UI Pluginas
|
|
77
|
+
// ===============================================================================================
|
|
78
|
+
|
|
79
|
+
const appConfig = _appConfig || {};
|
|
80
|
+
const excludes = appConfig.excludes || [];
|
|
81
|
+
const autoLoad = appConfig.autoLoad || [];
|
|
82
|
+
|
|
83
|
+
const serverMiddleware = [];
|
|
84
|
+
const autoLoadPackages = [];
|
|
85
|
+
const watcherIgnores = [
|
|
86
|
+
/.shell/,
|
|
87
|
+
/dist-pkg/,
|
|
88
|
+
/scripts\/standalone/
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
autoLoad.forEach((pkg) => {
|
|
92
|
+
// Need the version number of each file
|
|
93
|
+
const pkgPackageFile = require(path.join(dir, 'pkg', pkg, 'package.json'));
|
|
94
|
+
const pkgRef = `${ pkg }-${ pkgPackageFile.version }`;
|
|
95
|
+
|
|
96
|
+
autoLoadPackages.push({
|
|
97
|
+
name: `app-autoload-${ pkgRef }`,
|
|
98
|
+
content: `/pkg/${ pkgRef }/${ pkgRef }.umd.min.js`
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// Anything auto-loaded should also be excluded
|
|
102
|
+
if (!excludes.includes(pkg)) {
|
|
103
|
+
excludes.push(pkg);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Find any UI packages in node_modules
|
|
108
|
+
const NM = path.join(dir, 'node_modules');
|
|
109
|
+
const pkg = require(path.join(dir, 'package.json'));
|
|
110
|
+
const nmPackages = {};
|
|
111
|
+
|
|
112
|
+
if (pkg && pkg.dependencies) {
|
|
113
|
+
Object.keys(pkg.dependencies).forEach((pkg) => {
|
|
114
|
+
const f = require(path.join(NM, pkg, 'package.json'));
|
|
115
|
+
|
|
116
|
+
// The package.json must have the 'rancher' property to mark it as a UI package
|
|
117
|
+
if (f.rancher) {
|
|
118
|
+
const id = `${ f.name }-${ f.version }`;
|
|
119
|
+
|
|
120
|
+
nmPackages[id] = f.main;
|
|
121
|
+
|
|
122
|
+
// Add server middleware to serve up the files for this UI package
|
|
123
|
+
serverMiddleware.push({
|
|
124
|
+
path: `/pkg/${ id }`,
|
|
125
|
+
handler: serveStatic(path.join(NM, pkg))
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
serverMiddleware.push({
|
|
132
|
+
path: '/uiplugins-catalog',
|
|
133
|
+
handler: (req, res, next) => {
|
|
134
|
+
const p = req.url.split('?');
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
const proxy = createProxyMiddleware({
|
|
138
|
+
target: p[1],
|
|
139
|
+
pathRewrite: { '^.*': p[0] }
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
return proxy(req, res, next);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.error(e); // eslint-disable-line no-console
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
function includePkg(name) {
|
|
150
|
+
if (name.startsWith('.') || name === 'node_modules') {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return !excludes || (excludes && !excludes.includes(name));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
excludes.forEach((e) => {
|
|
158
|
+
watcherIgnores.push(new RegExp(`/pkg.${ e }`));
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// For each package in the pkg folder that is being compiled into the application,
|
|
162
|
+
// Add in the code to automatically import the types from that package
|
|
163
|
+
// This imports models, edit, detail, list etc
|
|
164
|
+
// When built as a UI package, shell/pkg/vue.config.js does the same thing
|
|
165
|
+
const autoImportTypes = {};
|
|
166
|
+
const VirtualModulesPlugin = require('webpack-virtual-modules');
|
|
167
|
+
let reqs = '';
|
|
168
|
+
const pkgFolder = path.relative(dir, './pkg');
|
|
169
|
+
|
|
170
|
+
if (fs.existsSync(pkgFolder)) {
|
|
171
|
+
const items = fs.readdirSync(path.relative(dir, './pkg'));
|
|
172
|
+
|
|
173
|
+
// Ignore hidden folders
|
|
174
|
+
items.filter(name => !name.startsWith('.')).forEach((name) => {
|
|
175
|
+
const f = require(path.join(dir, 'pkg', name, 'package.json'));
|
|
176
|
+
|
|
177
|
+
// Package file must have rancher field to be a plugin
|
|
178
|
+
if (includePkg(name) && f.rancher) {
|
|
179
|
+
reqs += `$plugin.initPlugin('${ name }', require(\'~/pkg/${ name }\')); `;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// // Serve the code for the UI package in case its used for dynamic loading (but not if the same package was provided in node_modules)
|
|
183
|
+
// if (!nmPackages[name]) {
|
|
184
|
+
// const pkgPackageFile = require(path.join(dir, 'pkg', name, 'package.json'));
|
|
185
|
+
// const pkgRef = `${ name }-${ pkgPackageFile.version }`;
|
|
186
|
+
|
|
187
|
+
// serverMiddleware.push({ path: `/pkg/${ pkgRef }`, handler: serveStatic(`${ dir }/dist-pkg/${ pkgRef }`) });
|
|
188
|
+
// }
|
|
189
|
+
autoImportTypes[`node_modules/@rancher/auto-import/${ name }`] = generateDynamicTypeImport(`@pkg/${ name }`, path.join(dir, `pkg/${ name }`));
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
Object.keys(nmPackages).forEach((m) => {
|
|
194
|
+
reqs += `$plugin.loadAsync('${ m }', '/pkg/${ m }/${ nmPackages[m] }');`;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Generate a virtual module '@rancher/dyanmic.js` which imports all of the packages that should be built into the application
|
|
198
|
+
// This is imported in 'shell/extensions/extension-loader.js` which ensures the all code for plugins to be included is imported in the application
|
|
199
|
+
const virtualModules = new VirtualModulesPlugin({ 'node_modules/@rancher/dynamic.js': `export default function ($plugin) { ${ reqs } };` });
|
|
200
|
+
const autoImport = new webpack.NormalModuleReplacementPlugin(/^@rancher\/auto-import$/, (resource) => {
|
|
201
|
+
const ctx = resource.context.split('/');
|
|
202
|
+
const pkg = ctx[ctx.length - 1];
|
|
203
|
+
|
|
204
|
+
resource.request = `@rancher/auto-import/${ pkg }`;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// @pkg imports must be resolved to the package that it importing them - this allows a package to use @pkg as an alis
|
|
208
|
+
// to the root of that particular package
|
|
209
|
+
const pkgImport = new webpack.NormalModuleReplacementPlugin(/^@pkg/, (resource) => {
|
|
210
|
+
const ctx = resource.context.split('/');
|
|
211
|
+
// Find 'pkg' folder in the contxt
|
|
212
|
+
const index = ctx.findIndex(s => s === 'pkg');
|
|
213
|
+
|
|
214
|
+
if (index !== -1 && (index + 1) < ctx.length) {
|
|
215
|
+
const pkg = ctx[index + 1];
|
|
216
|
+
let p = path.resolve(dir, 'pkg', pkg, resource.request.substr(5));
|
|
217
|
+
|
|
218
|
+
if (resource.request.startsWith(`@pkg/${ pkg }`)) {
|
|
219
|
+
p = path.resolve(dir, 'pkg', resource.request.substr(5));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
resource.request = p;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Serve up the dist-pkg folder under /pkg
|
|
227
|
+
serverMiddleware.push({ path: `/pkg/`, handler: serveStatic(`${ dir }/dist-pkg/`) });
|
|
228
|
+
// Endpoint to download and unpack a tgz from the local verdaccio rgistry (dev)
|
|
229
|
+
serverMiddleware.push(path.resolve(dir, SHELL, 'server', 'verdaccio-middleware'));
|
|
230
|
+
// Add the standard dashboard server middleware after the middleware added to serve up UI packages
|
|
231
|
+
serverMiddleware.push(path.resolve(dir, SHELL, 'server', 'server-middleware'));
|
|
232
|
+
|
|
233
|
+
// ===============================================================================================
|
|
234
|
+
// Dashboard nuxt configuration
|
|
235
|
+
// ===============================================================================================
|
|
236
|
+
|
|
237
|
+
require('events').EventEmitter.defaultMaxListeners = 20;
|
|
238
|
+
require('dotenv').config();
|
|
239
|
+
|
|
240
|
+
let routerBasePath = '/';
|
|
241
|
+
let resourceBase = '';
|
|
242
|
+
let outputDir = 'dist';
|
|
243
|
+
|
|
244
|
+
if ( typeof process.env.ROUTER_BASE !== 'undefined' ) {
|
|
245
|
+
routerBasePath = process.env.ROUTER_BASE;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if ( typeof process.env.RESOURCE_BASE !== 'undefined' ) {
|
|
249
|
+
resourceBase = process.env.RESOURCE_BASE;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if ( typeof process.env.OUTPUT_DIR !== 'undefined' ) {
|
|
253
|
+
outputDir = process.env.OUTPUT_DIR;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if ( resourceBase && !resourceBase.endsWith('/') ) {
|
|
257
|
+
resourceBase += '/';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Store the Router Base as env variable that we can use in `nuxt/router.js`
|
|
261
|
+
process.env.VUE_APP_ROUTER_BASE = routerBasePath;
|
|
262
|
+
|
|
263
|
+
console.log(`Build: ${ dev ? 'Development' : 'Production' }`); // eslint-disable-line no-console
|
|
264
|
+
|
|
265
|
+
if ( !dev ) {
|
|
266
|
+
console.log(`Version: ${ dashboardVersion }`); // eslint-disable-line no-console
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if ( !dev ) {
|
|
270
|
+
console.log(`Version: ${ dashboardVersion }`); // eslint-disable-line no-console
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if ( resourceBase ) {
|
|
274
|
+
console.log(`Resource Base URL: ${ resourceBase }`); // eslint-disable-line no-console
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if ( routerBasePath !== '/' ) {
|
|
278
|
+
console.log(`Router Base Path: ${ routerBasePath }`); // eslint-disable-line no-console
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if ( pl !== STANDARD ) {
|
|
282
|
+
console.log(`PL: ${ pl }`); // eslint-disable-line no-console
|
|
283
|
+
}
|
|
284
|
+
const rancherEnv = process.env.RANCHER_ENV || 'web';
|
|
285
|
+
|
|
286
|
+
console.log(`API: '${ api }'. Env: '${ rancherEnv }'`); // eslint-disable-line no-console
|
|
287
|
+
const proxy = {
|
|
288
|
+
...appConfig.proxies,
|
|
289
|
+
'/k8s': proxyWsOpts(api), // Straight to a remote cluster (/k8s/clusters/<id>/)
|
|
290
|
+
'/pp': proxyWsOpts(api), // For (epinio) standalone API
|
|
291
|
+
'/api': proxyWsOpts(api), // Management k8s API
|
|
292
|
+
'/apis': proxyWsOpts(api), // Management k8s API
|
|
293
|
+
'/v1': proxyWsOpts(api), // Management Steve API
|
|
294
|
+
'/v3': proxyWsOpts(api), // Rancher API
|
|
295
|
+
'/v3-public': proxyOpts(api), // Rancher Unauthed API
|
|
296
|
+
'/api-ui': proxyOpts(api), // Browser API UI
|
|
297
|
+
'/meta': proxyMetaOpts(api), // Browser API UI
|
|
298
|
+
'/v1-*': proxyOpts(api), // SAML, KDM, etc
|
|
299
|
+
'/rancherversion': proxyPrimeOpts(api), // Rancher version endpoint
|
|
300
|
+
// These are for Ember embedding
|
|
301
|
+
'/c/*/edit': proxyOpts('https://127.0.0.1:8000'), // Can't proxy all of /c because that's used by Vue too
|
|
302
|
+
'/k/': proxyOpts('https://127.0.0.1:8000'),
|
|
303
|
+
'/g/': proxyOpts('https://127.0.0.1:8000'),
|
|
304
|
+
'/n/': proxyOpts('https://127.0.0.1:8000'),
|
|
305
|
+
'/p/': proxyOpts('https://127.0.0.1:8000'),
|
|
306
|
+
'/assets': proxyOpts('https://127.0.0.1:8000'),
|
|
307
|
+
'/translations': proxyOpts('https://127.0.0.1:8000'),
|
|
308
|
+
'/engines-dist': proxyOpts('https://127.0.0.1:8000'),
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const config = {
|
|
312
|
+
// Vue server
|
|
313
|
+
devServer: {
|
|
314
|
+
https: (devPorts ? {
|
|
315
|
+
key: fs.readFileSync(path.resolve(__dirname, 'server/server.key')),
|
|
316
|
+
cert: fs.readFileSync(path.resolve(__dirname, 'server/server.crt'))
|
|
317
|
+
} : null),
|
|
318
|
+
port: (devPorts ? 8005 : 80),
|
|
319
|
+
host: '0.0.0.0',
|
|
320
|
+
public: `https://0.0.0.0:${ devPorts ? 8005 : 80 }`,
|
|
321
|
+
before(app, server) {
|
|
322
|
+
const socketProxies = {};
|
|
323
|
+
|
|
324
|
+
Object.keys(proxy).forEach((p) => {
|
|
325
|
+
const px = createProxyMiddleware({
|
|
326
|
+
...proxy[p],
|
|
327
|
+
ws: false // We will handle the web socket upgrade
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
if (proxy[p].ws) {
|
|
331
|
+
socketProxies[p] = px;
|
|
332
|
+
}
|
|
333
|
+
app.use(p, px);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
server.websocketProxies.push({
|
|
337
|
+
upgrade(req, socket, head) {
|
|
338
|
+
const path = Object.keys(socketProxies).find(path => req.url.startsWith(path));
|
|
339
|
+
|
|
340
|
+
if (path) {
|
|
341
|
+
const proxy = socketProxies[path];
|
|
342
|
+
|
|
343
|
+
if (proxy.upgrade) {
|
|
344
|
+
proxy.upgrade(req, socket, head);
|
|
345
|
+
} else {
|
|
346
|
+
console.log(`Upgrade for Proxy is not defined. Cannot upgrade Web socket for ${ req.url }`); // eslint-disable-line no-console
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
console.log(`Unknown Web socket upgrade request for ${ req.url }`); // eslint-disable-line no-console
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
publicPath: resourceBase || undefined,
|
|
356
|
+
css: {
|
|
357
|
+
loaderOptions: {
|
|
358
|
+
sass: {
|
|
359
|
+
// This is effectively added to the beginning of each style that's imported or included in a vue file. We may want to look into including these in app.scss
|
|
360
|
+
additionalData: `
|
|
361
|
+
@use 'sass:math';
|
|
362
|
+
@import "~shell/assets/styles/base/_variables.scss";
|
|
363
|
+
@import "~shell/assets/styles/base/_functions.scss";
|
|
364
|
+
@import "~shell/assets/styles/base/_mixins.scss";
|
|
365
|
+
`
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
|
|
370
|
+
outputDir,
|
|
371
|
+
|
|
372
|
+
pages: {
|
|
373
|
+
index: {
|
|
374
|
+
entry: path.join(SHELL_ABS, '/nuxt/client.js'),
|
|
375
|
+
template: path.join(SHELL_ABS, '/public/index.html')
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
|
|
379
|
+
configureWebpack(config) {
|
|
380
|
+
config.resolve.alias['~'] = dir;
|
|
381
|
+
config.resolve.alias['@'] = dir;
|
|
382
|
+
config.resolve.alias['~assets'] = path.join(__dirname, 'assets');
|
|
383
|
+
config.resolve.alias['~shell'] = SHELL_ABS;
|
|
384
|
+
config.resolve.alias['@shell'] = SHELL_ABS;
|
|
385
|
+
config.resolve.alias['@pkg'] = path.join(dir, 'pkg');
|
|
386
|
+
config.resolve.alias['./node_modules'] = path.join(dir, 'node_modules');
|
|
387
|
+
config.resolve.alias['@components'] = COMPONENTS_DIR;
|
|
388
|
+
config.resolve.modules.push(__dirname);
|
|
389
|
+
config.plugins.push(virtualModules);
|
|
390
|
+
config.plugins.push(autoImport);
|
|
391
|
+
config.plugins.push(new VirtualModulesPlugin(autoImportTypes));
|
|
392
|
+
config.plugins.push(pkgImport);
|
|
393
|
+
// DefinePlugin does string replacement within our code. We may want to consider replacing it with something else. In code we'll see something like
|
|
394
|
+
// process.env.commit even though process and env aren't even defined objects. This could cause people to be mislead.
|
|
395
|
+
config.plugins.push(new webpack.DefinePlugin({
|
|
396
|
+
'process.client': JSON.stringify(true),
|
|
397
|
+
'process.env.commit': JSON.stringify(commit),
|
|
398
|
+
'process.env.version': JSON.stringify(dashboardVersion),
|
|
399
|
+
'process.env.dev': JSON.stringify(dev),
|
|
400
|
+
'process.env.pl': JSON.stringify(pl),
|
|
401
|
+
'process.env.perfTest': JSON.stringify(perfTest),
|
|
402
|
+
'process.env.rancherEnv': JSON.stringify(rancherEnv),
|
|
403
|
+
'process.env.harvesterPkgUrl': JSON.stringify(process.env.HARVESTER_PKG_URL),
|
|
404
|
+
'process.env.api': JSON.stringify(api),
|
|
405
|
+
|
|
406
|
+
// This is a replacement of the nuxt publicRuntimeConfig
|
|
407
|
+
'nuxt.publicRuntimeConfig': JSON.stringify({
|
|
408
|
+
rancherEnv,
|
|
409
|
+
dashboardVersion
|
|
410
|
+
}),
|
|
411
|
+
}));
|
|
412
|
+
|
|
413
|
+
// The static assets need to be in the built public folder in order to get served (primarily the favicon for now)
|
|
414
|
+
config.plugins.push(new CopyWebpackPlugin([{ from: path.join(SHELL_ABS, 'static'), to: 'public' }]));
|
|
415
|
+
|
|
416
|
+
config.resolve.extensions.push(...['.tsx', '.ts', '.js', '.vue', '.scss']);
|
|
417
|
+
config.watchOptions = config.watchOptions || {};
|
|
418
|
+
config.watchOptions.ignored = watcherIgnores;
|
|
419
|
+
|
|
420
|
+
if (dev) {
|
|
421
|
+
config.devtool = 'cheap-module-source-map';
|
|
422
|
+
} else {
|
|
423
|
+
config.devtool = 'source-map';
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
config.resolve.symlinks = false;
|
|
427
|
+
|
|
428
|
+
// Ensure we process files in the @rancher/shell folder
|
|
429
|
+
config.module.rules.forEach((r) => {
|
|
430
|
+
if ('test.js'.match(r.test)) {
|
|
431
|
+
if (r.exclude) {
|
|
432
|
+
const orig = r.exclude;
|
|
433
|
+
|
|
434
|
+
r.exclude = function(modulePath) {
|
|
435
|
+
if (modulePath.indexOf(SHELL_ABS) === 0 || typeof orig !== 'function') {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return orig(modulePath);
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// Instrument code for tests
|
|
446
|
+
const babelPlugins = [
|
|
447
|
+
// TODO: Browser support
|
|
448
|
+
// ['@babel/plugin-transform-modules-commonjs'],
|
|
449
|
+
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
|
|
450
|
+
['@babel/plugin-proposal-class-properties', { loose: true }]
|
|
451
|
+
];
|
|
452
|
+
|
|
453
|
+
if (instrumentCode) {
|
|
454
|
+
babelPlugins.push('babel-plugin-istanbul');
|
|
455
|
+
|
|
456
|
+
console.warn('Instrumenting code for coverage'); // eslint-disable-line no-console
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const loaders = [
|
|
460
|
+
// Ensure there is a fallback for browsers that don't support web workers
|
|
461
|
+
{
|
|
462
|
+
test: /web-worker.[a-z-]+.js/i,
|
|
463
|
+
loader: 'worker-loader',
|
|
464
|
+
options: { inline: 'fallback' },
|
|
465
|
+
},
|
|
466
|
+
// Handler for csv files (e.g. ec2 instance data)
|
|
467
|
+
{
|
|
468
|
+
test: /\.csv$/i,
|
|
469
|
+
loader: 'csv-loader',
|
|
470
|
+
options: {
|
|
471
|
+
dynamicTyping: true,
|
|
472
|
+
header: true,
|
|
473
|
+
skipEmptyLines: true
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
// Handler for yaml files (used for i18n files, for example)
|
|
477
|
+
{
|
|
478
|
+
test: /\.ya?ml$/i,
|
|
479
|
+
loader: 'js-yaml-loader',
|
|
480
|
+
options: { name: '[path][name].[ext]' },
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
test: /\.m?[tj]sx?$/,
|
|
484
|
+
// This excludes no modules except for node_modules/@rancher/... so that plugins can properly compile
|
|
485
|
+
// when referencing @rancher/shell
|
|
486
|
+
exclude: /node_modules\/(?!(@rancher)\/).*/,
|
|
487
|
+
use: [
|
|
488
|
+
{
|
|
489
|
+
loader: 'cache-loader',
|
|
490
|
+
options: {
|
|
491
|
+
cacheDirectory: 'node_modules/.cache/babel-loader',
|
|
492
|
+
cacheIdentifier: 'e93f32da'
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
loader: 'babel-loader',
|
|
497
|
+
options: {
|
|
498
|
+
presets: [
|
|
499
|
+
[
|
|
500
|
+
require.resolve('@nuxt/babel-preset-app'),
|
|
501
|
+
{
|
|
502
|
+
corejs: { version: 3 },
|
|
503
|
+
targets: { browsers: ['last 2 versions'] },
|
|
504
|
+
modern: true
|
|
505
|
+
}
|
|
506
|
+
],
|
|
507
|
+
'@babel/preset-typescript',
|
|
508
|
+
],
|
|
509
|
+
plugins: babelPlugins
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
]
|
|
513
|
+
},
|
|
514
|
+
{
|
|
515
|
+
test: /\.tsx?$/,
|
|
516
|
+
use: [
|
|
517
|
+
{
|
|
518
|
+
loader: 'cache-loader',
|
|
519
|
+
options: {
|
|
520
|
+
cacheDirectory: 'node_modules/.cache/ts-loader',
|
|
521
|
+
cacheIdentifier: '3596741e'
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
loader: 'ts-loader',
|
|
526
|
+
options: {
|
|
527
|
+
transpileOnly: true,
|
|
528
|
+
happyPackMode: false,
|
|
529
|
+
appendTsxSuffixTo: [
|
|
530
|
+
'\\.vue$'
|
|
531
|
+
],
|
|
532
|
+
configFile: path.join(SHELL_ABS, 'tsconfig.json')
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
]
|
|
536
|
+
},
|
|
537
|
+
// Prevent warning in log with the md files in the content folder
|
|
538
|
+
{
|
|
539
|
+
test: /\.md$/,
|
|
540
|
+
use: [
|
|
541
|
+
{
|
|
542
|
+
loader: 'url-loader',
|
|
543
|
+
options: {
|
|
544
|
+
name: '[path][name].[ext]',
|
|
545
|
+
limit: 1,
|
|
546
|
+
esModule: false
|
|
547
|
+
},
|
|
548
|
+
}
|
|
549
|
+
]
|
|
550
|
+
},
|
|
551
|
+
// Prevent warning in log with the md files in the content folder
|
|
552
|
+
{
|
|
553
|
+
test: /\.md$/,
|
|
554
|
+
use: [
|
|
555
|
+
{
|
|
556
|
+
loader: 'frontmatter-markdown-loader',
|
|
557
|
+
options: { mode: ['body'] }
|
|
558
|
+
}
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
];
|
|
562
|
+
|
|
563
|
+
config.module.rules.push(...loaders);
|
|
564
|
+
},
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
return config;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// ===============================================================================================
|
|
571
|
+
// Functions for the request proxying used in dev
|
|
572
|
+
// ===============================================================================================
|
|
573
|
+
|
|
574
|
+
function proxyMetaOpts(target) {
|
|
575
|
+
return {
|
|
576
|
+
target,
|
|
577
|
+
followRedirects: true,
|
|
578
|
+
secure: !dev,
|
|
579
|
+
changeOrigin: true,
|
|
580
|
+
onProxyReq,
|
|
581
|
+
onProxyReqWs,
|
|
582
|
+
onError,
|
|
583
|
+
onProxyRes,
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function proxyOpts(target) {
|
|
588
|
+
return {
|
|
589
|
+
target,
|
|
590
|
+
secure: !devPorts,
|
|
591
|
+
changeOrigin: true,
|
|
592
|
+
onProxyReq,
|
|
593
|
+
onProxyReqWs,
|
|
594
|
+
onError,
|
|
595
|
+
onProxyRes
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// Intercept the /rancherversion API call wnad modify the 'RancherPrime' value
|
|
600
|
+
// if configured to do so by the environment variable PRIME
|
|
601
|
+
function proxyPrimeOpts(target) {
|
|
602
|
+
const opts = proxyOpts(target);
|
|
603
|
+
|
|
604
|
+
// Don't intercept if the PRIME environment variable is not set
|
|
605
|
+
if (!prime?.length) {
|
|
606
|
+
return opts;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
opts.onProxyRes = (proxyRes, req, res) => {
|
|
610
|
+
const _end = res.end;
|
|
611
|
+
let body = '';
|
|
612
|
+
|
|
613
|
+
proxyRes.on( 'data', (data) => {
|
|
614
|
+
data = data.toString('utf-8');
|
|
615
|
+
body += data;
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
res.write = () => {};
|
|
619
|
+
|
|
620
|
+
res.end = () => {
|
|
621
|
+
let output = body;
|
|
622
|
+
|
|
623
|
+
try {
|
|
624
|
+
const out = JSON.parse(body);
|
|
625
|
+
|
|
626
|
+
out.RancherPrime = prime;
|
|
627
|
+
output = JSON.stringify(out);
|
|
628
|
+
} catch (err) {}
|
|
629
|
+
|
|
630
|
+
res.setHeader('content-length', output.length );
|
|
631
|
+
res.setHeader('content-type', 'application/json' );
|
|
632
|
+
res.setHeader('transfer-encoding', '');
|
|
633
|
+
res.setHeader('cache-control', 'no-cache');
|
|
634
|
+
res.writeHead(proxyRes.statusCode);
|
|
635
|
+
_end.apply(res, [output]);
|
|
636
|
+
};
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
return opts;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function onProxyRes(proxyRes, req, res) {
|
|
643
|
+
if (devPorts) {
|
|
644
|
+
proxyRes.headers['X-Frame-Options'] = 'ALLOWALL';
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function proxyWsOpts(target) {
|
|
649
|
+
return {
|
|
650
|
+
...proxyOpts(target),
|
|
651
|
+
ws: true,
|
|
652
|
+
changeOrigin: true,
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
function onProxyReq(proxyReq, req) {
|
|
657
|
+
if (!(proxyReq._currentRequest && proxyReq._currentRequest._headerSent)) {
|
|
658
|
+
proxyReq.setHeader('x-api-host', req.headers['host']);
|
|
659
|
+
proxyReq.setHeader('x-forwarded-proto', 'https');
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function onProxyReqWs(proxyReq, req, socket, options, head) {
|
|
664
|
+
req.headers.origin = options.target.href;
|
|
665
|
+
proxyReq.setHeader('origin', options.target.href);
|
|
666
|
+
proxyReq.setHeader('x-api-host', req.headers['host']);
|
|
667
|
+
proxyReq.setHeader('x-forwarded-proto', 'https');
|
|
668
|
+
// console.log(proxyReq.getHeaders());
|
|
669
|
+
|
|
670
|
+
socket.on('error', (err) => {
|
|
671
|
+
console.error('Proxy WS Error:', err); // eslint-disable-line no-console
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
function onError(err, req, res) {
|
|
676
|
+
res.statusCode = 598;
|
|
677
|
+
console.error('Proxy Error:', err); // eslint-disable-line no-console
|
|
678
|
+
res.write(JSON.stringify(err));
|
|
679
|
+
}
|