MCPcopy
hub / github.com/docmirror/dev-sidecar / setProxy

Function setProxy

packages/core/src/modules/plugin/node/index.js:124–167  ·  view source on GitHub ↗
(ip, port)

Source from the content-addressed store, hash-verified

122 },
123
124 async setProxy (ip, port) {
125 const command = config.get().plugin.node.setting.command || 'npm'
126
127 const cmds = [
128 `${command} config set proxy=http://${ip}:${port - 1}`,
129 `${command} config set https-proxy=http://${ip}:${port}`,
130 ]
131
132 const env = []
133
134 /**
135 * 'strict-ssl': false,
136 * 'cafile': true,
137 * 'NODE_EXTRA_CA_CERTS': true,
138 * 'NODE_TLS_REJECT_UNAUTHORIZED': false
139 */
140 const nodeConfig = config.get().plugin.node
141 const rootCaCertFile = config.get().server.setting.rootCaFile.certPath
142 if (nodeConfig.setting['strict-ssl']) {
143 cmds.push(`${command} config set strict-ssl false`)
144 }
145 if (nodeConfig.setting.cafile) {
146 cmds.push(`${command} config set cafile "${rootCaCertFile}"`)
147 }
148
149 if (nodeConfig.setting.NODE_EXTRA_CA_CERTS) {
150 cmds.push(`${command} config set NODE_EXTRA_CA_CERTS "${rootCaCertFile}"`)
151 env.push({ key: 'NODE_EXTRA_CA_CERTS', value: rootCaCertFile })
152 }
153
154 if (nodeConfig.setting.NODE_TLS_REJECT_UNAUTHORIZED) {
155 cmds.push(`${command} config set NODE_TLS_REJECT_UNAUTHORIZED 0`)
156 env.push({ key: 'NODE_TLS_REJECT_UNAUTHORIZED', value: '0' })
157 }
158
159 const ret = await shell.exec(cmds, { type: 'cmd' })
160 if (env.length > 0) {
161 await shell.setSystemEnv({ list: env })
162 }
163 event.fire('status', { key: 'plugin.node.enabled', value: true })
164 log.info('开启【NPM】代理成功')
165
166 return ret
167 },
168
169 async unsetProxy () {
170 const command = config.get().plugin.node.setting.command || 'npm'

Callers

nothing calls this directly

Calls 2

getMethod · 0.80
execMethod · 0.45

Tested by

no test coverage detected