Skip to content

Commit

Permalink
fix: fetch, code: node 20 (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiroaisen authored Apr 28, 2024
2 parents 6bf3126 + b40e952 commit ae26b77
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 146 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/front-admin-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run ci
working-directory: ./front

- run: npm run build --if-present
working-directory: ./front/packages/client

- run: npm run build --if-present
7 changes: 6 additions & 1 deletion .github/workflows/front-admin-typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run ci
working-directory: ./front

- run: npm run build --if-present
working-directory: ./front/packages/client

- run: npm run check
7 changes: 6 additions & 1 deletion .github/workflows/front-server-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- name: Skip Duplicate Actions
Expand All @@ -48,6 +48,11 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run ci
working-directory: ./front

- run: npm run build --if-present
working-directory: ./front/packages/client

- run: npm run build --if-present
7 changes: 6 additions & 1 deletion .github/workflows/front-server-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run ci
working-directory: ./front

- run: npm run build --if-present
working-directory: ./front/packages/client

- run: npm test
7 changes: 6 additions & 1 deletion .github/workflows/front-studio-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run ci
working-directory: ./front

- run: npm run build --if-present
working-directory: ./front/packages/client

- run: npm run build --if-present
7 changes: 6 additions & 1 deletion .github/workflows/front-studio-typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- run: npm run ci
working-directory: ./front

- run: npm run build --if-present
working-directory: ./front/packages/client

- run: npm run check
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:

Expand Down
2 changes: 1 addition & 1 deletion front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "run-s install:share install:server install:admin install:app",
"install": "run-s install:share install:client install:server install:admin install:app",
"install:share": "cd share && npm i",
"install:server": "cd server && npm i",
"install:admin": "cd admin && npm i",
Expand Down
4 changes: 2 additions & 2 deletions front/packages/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions front/packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import type { PublicErrorCode } from "./defs/error/PublicErrorCode.js";

export { ClientError, type ClientErrorCode };

import http from "http";
import https from "https";

http.globalAgent = new http.Agent({ keepAlive: false, maxSockets: Infinity });
https.globalAgent = new https.Agent({ keepAlive: false, maxSockets: Infinity });

const http_agent = new http.Agent({ keepAlive: false, maxSockets: Infinity })
const https_agent = new https.Agent({ keepAlive: false, maxSockets: Infinity })

const qss = (v: any) => {
return qs.stringify(v, { addQueryPrefix: true, skipNulls: true })
}
Expand Down Expand Up @@ -62,7 +71,7 @@ export class Client {
const method = init.method ?? "GET";
// this.logger.debug(`fetch: ${method} ${url}`);
return await this.node_fetch(url, {
agent: false,
agent: url => url.protocol === "http:" ? http_agent : https_agent,
...init
}).catch(e => {
// this.logger.warn(`fetch error: ${e} | cause=${e.cause}`)
Expand Down Expand Up @@ -109,7 +118,6 @@ export class Client {

// remove default user agent
headers.append("user-agent", ua || "openstream-unknown")
headers.append("connection", "close")

if (token) headers.append(ACCESS_TOKEN_HEADER, token);

Expand Down Expand Up @@ -511,7 +519,6 @@ export class StationPictures {

if (ip) headers.append(FORWARD_IP_HEADER, ip)
if (ua) headers.append("user-agent", ua)
headers.append("connection", "close")
headers.append(ACCESS_TOKEN_HEADER, token)
headers.append("content-type", "application/octet-stream")

Expand Down Expand Up @@ -627,7 +634,6 @@ export class StationFiles {

if (ip) headers.append(FORWARD_IP_HEADER, ip)
if (ua) headers.append("user-agent", ua)
headers.append("connection", "close")
headers.append(ACCESS_TOKEN_HEADER, token)
headers.append("content-type", content_type)
headers.append("content-length", String(content_length))
Expand Down
Loading

0 comments on commit ae26b77

Please sign in to comment.