Skip to content

Commit

Permalink
fix: wait for fluentci studio server to start
Browse files Browse the repository at this point in the history
fix: wait for fluentci studio server to start
  • Loading branch information
tsirysndr committed May 27, 2024
1 parent ea91eae commit ae1a27f
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions src/cmd/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,68 +70,68 @@ async function studio({ port }: { port?: number }) {
},
}).spawn();

child.status.then(async ({ code }) => {
child.status.then(({ code }) => {
if (code !== 0) {
console.error("Failed to start FluentCI Studio");
Deno.exit(1);
}
});

await sleep(1000); // wait for the studio to start
await sleep(1000); // wait for the studio to start

Deno.serve(
{
port: port || 6076,
onListen: () => {
const PORT = port || 6076;
console.log(
`${green("FluentCI Studio")} is up and running on ${cyan(
`http://localhost:${PORT}`
)}`
);
open(`http://localhost:${PORT}/project/${projectId}`).catch((err) => {
console.error(err);
});
},
Deno.serve(
{
port: port || 6076,
onListen: () => {
const PORT = port || 6076;
console.log(
`${green("FluentCI Studio")} is up and running on ${cyan(
`http://localhost:${PORT}`
)}`
);
open(`http://localhost:${PORT}/project/${projectId}`).catch((err) => {
console.error(err);
});
},
async (req) => {
const upgrade = req.headers.get("upgrade") || "";
if (upgrade.toLowerCase() === "websocket") {
const ws = Deno.upgradeWebSocket(req);
const id = createId();
sockets[id] = ws.socket;

sockets[id].onmessage = (e) => {
if (e.data !== "ping") {
console.log("> socket message:", e.data);
}
sockets[id]?.send(new Date().toString());
};
sockets[id].onerror = (e) =>
console.log("socket errored:", (e as unknown as Error).message);
sockets[id].onclose = () => delete sockets[id];
},
async (req) => {
const upgrade = req.headers.get("upgrade") || "";
if (upgrade.toLowerCase() === "websocket") {
const ws = Deno.upgradeWebSocket(req);
const id = createId();
sockets[id] = ws.socket;

return ws.response;
}
sockets[id].onmessage = (e) => {
if (e.data !== "ping") {
console.log("> socket message:", e.data);
}
sockets[id]?.send(new Date().toString());
};
sockets[id].onerror = (e) =>
console.log("socket errored:", (e as unknown as Error).message);
sockets[id].onclose = () => delete sockets[id];

const url = new URL(req.url);
if (
url.pathname.endsWith("/graphql") ||
url.pathname.endsWith("/graphiql")
) {
return yoga(req);
}
url.protocol = "http";
url.hostname = "127.0.0.1";
url.port = FLUENTCI_STUDIO_PORT;
return ws.response;
}

return await fetch(url.href, {
headers: req.headers,
method: req.method,
body: req.body,
});
const url = new URL(req.url);
if (
url.pathname.endsWith("/graphql") ||
url.pathname.endsWith("/graphiql")
) {
return yoga(req);
}
);
});
url.protocol = "http";
url.hostname = "127.0.0.1";
url.port = FLUENTCI_STUDIO_PORT;

return await fetch(url.href, {
headers: req.headers,
method: req.method,
body: req.body,
});
}
);
}

export default studio;

0 comments on commit ae1a27f

Please sign in to comment.