Skip to content

Commit

Permalink
fix: translate fail when use http proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ipcjs committed Oct 23, 2023
1 parent f4933ca commit 486ec08
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"parse-gitignore": "^1.0.1",
"pofile": "^1.1.1",
"properties": "^1.2.1",
"proxy-agent": "^6.3.1",
"qs": "^6.10.3",
"semver": "^7.5.2",
"string-similarity": "^4.0.4",
Expand Down
6 changes: 6 additions & 0 deletions src/translators/engines/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import axios from 'axios'
import { ProxyAgent } from 'proxy-agent'

axios.defaults.httpAgent = axios.defaults.httpsAgent = new ProxyAgent()
axios.defaults.proxy = false

export interface TranslateEngineConfig {
timeout?: number
apiKey?: string
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"allowJs": true,
"declaration": true,
"moduleResolution": "node",
"skipLibCheck": true,
Expand Down
12 changes: 10 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ const config = {
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
test: /\.(ts|js)$/,
exclude: {
include: /node_modules/,
not: [
// The "proxy-agent" related library uses optional chaining feature and requires conversion using "ts-loader."
/node_modules[\\\/](\w+-)?proxy-agent/,
/node_modules[\\\/](get-uri|agent-base|degenerator)/,
/node_modules[\\\/]@tootallnate[\\\/]quickjs-emscripten/,
],
},
use: [
{
loader: 'ts-loader',
Expand Down
Loading

0 comments on commit 486ec08

Please sign in to comment.