Skip to content

Commit

Permalink
clean up agent checks for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Nov 15, 2024
1 parent 825d069 commit d9cfe08
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/pty-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"build": "tsc",
"clean": "rm -rf .turbo node_modules",
"dev:t": "pnpm with-env tsx watch --clear-screen=false src/index.ts",
"dev": "pnpm with-env tsx watch --clear-screen=false src/index.ts",
"lint": "eslint",
"format": "prettier --check . --ignore-path ../../.gitignore",
"with-env": "dotenv -e ../../.env --"
Expand Down
6 changes: 4 additions & 2 deletions apps/pty-proxy/src/controller/agent-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ export class AgentSocket {
throw new Error("User does not have access.");
}

return new AgentSocket(socket, name, workspace.id);
const agent = new AgentSocket(socket, name, workspace.id);
await agent.updateResource({});
return agent;
}

private resource: ResourceToInsert | null = null;
resource: ResourceToInsert | null = null;

private constructor(
private readonly socket: WebSocket,
Expand Down
11 changes: 7 additions & 4 deletions apps/pty-proxy/src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import { UserSocket } from "./user-socket.js";
const onConnect = async (ws: WebSocket, request: IncomingMessage) => {
const agent = await AgentSocket.from(ws, request);
if (agent != null) {
logger.info("Agent connected", {
resourceId: agent.resource.id,
name: agent.resource.name,
});
logger.info("Agent connected");
if (agent.resource?.id == null) {
logger.error("Agent resource id is null");
ws.close();
throw new Error("Agent resource id is null");
}

agents.set(agent.resource.id, agent);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/pty-proxy/src/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const addSocket = (expressApp: Express) => {
}

const { pathname } = new URL(request.url, "ws://base.ws");
if (pathname.startsWith("/api/v1/target/proxy/session")) {
if (pathname.startsWith("/api/v1/resources/proxy/session")) {
sessionOnUpgrade(request, socket, head);
return;
}

if (pathname.startsWith("/api/v1/target/proxy/controller")) {
if (pathname.startsWith("/api/v1/resources/proxy/controller")) {
controllerOnUpgrade(request, socket, head);
return;
}
Expand Down
25 changes: 13 additions & 12 deletions apps/webservice/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ const config = {
],
},

// async rewrites() {
// return [
// {
// source: "/api/v1/target/proxy/controller",
// destination: "http://localhost:4000/api/v1/target/proxy/controller",
// },
// {
// source: "/api/v1/target/proxy/session/:path*",
// destination: "http://localhost:4000/api/v1/target/proxy/session/:path*",
// },
// ];
// },
async rewrites() {
return [
{
source: "/api/v1/resources/proxy/controller",
destination: "http://localhost:4000/api/v1/resources/proxy/controller",
},
{
source: "/api/v1/resources/proxy/session/:path*",
destination:
"http://localhost:4000/api/v1/resources/proxy/session/:path*",
},
];
},
/** We already do linting and typechecking as separate tasks in CI */
eslint: { ignoreDuringBuilds: true },
typescript: { ignoreBuildErrors: true },
Expand Down

0 comments on commit d9cfe08

Please sign in to comment.