Skip to content

Commit

Permalink
fix: Nodejs fetch error relate to (nodejs/node#46221)
Browse files Browse the repository at this point in the history
  • Loading branch information
499070844 committed Oct 31, 2024
1 parent 9e17948 commit 384133e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@types/node": "^22.7.5",
"dprint": "^0.47.4"
"dprint": "^0.47.4",
"typescript": "^5.6.3"
}
}
}
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

35 changes: 19 additions & 16 deletions src/frontend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ frontend.all("/api/*", (c) => {
const { method, path, raw } = c.req;
const { EZ_PIPELINE_STREAMS2_NOTIFICATION_LETTER_ADDR } = env(c);
console.log("env: ", EZ_PIPELINE_STREAMS2_NOTIFICATION_LETTER_ADDR);
const reqOptions: RequestInit = {
const reqOptions: RequestInit & { duplex: 'half' } = {
method,
...(raw.body && { body: raw.body }),
headers: raw.headers,
duplex: 'half'
};
return fetch(`${EZ_PIPELINE_STREAMS2_NOTIFICATION_LETTER_ADDR}${path}`, reqOptions);
});
Expand All @@ -72,7 +73,7 @@ frontend.get("/resources/*", async (c) => {
let stat: fs.Stats | undefined;
try {
stat = fs.statSync(absolutPath);
} catch {}
} catch { }

console.log("get path", absolutPath);
console.info(stat);
Expand Down Expand Up @@ -107,6 +108,22 @@ frontend.get("/web", async (c) => {
return c.html(content);
});


frontend.post("/pipeline/streams2/frontend/activeBranch/:commitId", async (c) => {
const { commitId } = c.req.param();
const myEnv = env(c);
const { availableBranches } = await readFrontendState(myEnv);
const branchInfo = availableBranches.find((value) => value.name.includes(commitId));
if (!branchInfo) {
return c.notFound();
}
await writeFrontendState("activeBranch", branchInfo.name, myEnv);
await writeFrontendState("activeResourcesPath", branchInfo.path, myEnv);
return c.json({
msg: "The given branch is considered active",
});
});

frontend.post("/pipeline/streams2/frontend/:branchName/:commitId", async (c) => {
console.log("trigger streams2 frontend pipeline");
const { commitId, branchName } = c.req.param();
Expand Down Expand Up @@ -148,19 +165,5 @@ frontend.get("/pipeline/streams2/frontend", async (c) => {
});
});

frontend.post("/pipeline/streams2/frontend/activeBranch/:commitId", async (c) => {
const { commitId } = c.req.param();
const myEnv = env(c);
const { availableBranches } = await readFrontendState(myEnv);
const branchInfo = availableBranches.find((value) => value.name.includes(commitId));
if (!branchInfo) {
return c.notFound();
}
await writeFrontendState("activeBranch", branchInfo.name, myEnv);
await writeFrontendState("activeResourcesPath", branchInfo.path, myEnv);
return c.json({
msg: "The given branch is considered active",
});
});

export default frontend;
6 changes: 3 additions & 3 deletions src/lib/pipeline/streams2-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function startPipeline(env: EnvSchemaType, branchName: string, comm
pipe.use(async (ctx, next) => {
await pipeTitle(ctx.logStream, "Step 2: pnpm run lint");
console.log("start to run pnpm install");
const handler2 = exec("pnpm run lint", { cwd: env.EZ_PIPELINE_STREAMS2_FRONTEND });
const handler2 = exec("pnpm run lint:sit", { cwd: env.EZ_PIPELINE_STREAMS2_FRONTEND });
if (!handler2.stderr || !handler2.stdout) {
throw new Error("no stderr or stdout");
}
Expand All @@ -48,7 +48,7 @@ export async function startPipeline(env: EnvSchemaType, branchName: string, comm
const [code, signals] = await promiseFromChildProcess(handler2);
if (code !== 0) {
ctx.pipeStatus.writePipelineStatu("Failure", 0);
console.error("pipeline fail on pnpm run lint");
console.error("pipeline fail on pnpm run lint:sit");
return;
}
console.log("after exec pnpm run lint");
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function startPipeline(env: EnvSchemaType, branchName: string, comm
console.error("pipeline fail on pnpm run build");
return;
}
console.log("after exec pnpm run lint");
console.log("after exec pnpm run build:odc");
console.log("installation exit by", code);
console.log("installation singals is", signals);
console.log("the stream is writeable", ctx.logStream.writable);
Expand Down

0 comments on commit 384133e

Please sign in to comment.