Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions packages/trpc/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,40 @@ import { configs } from "./utils/configs";
import { k8sApi } from "./utils/k8s";

const app = express();
app.use(cors({ origin: "*" }));
app.use(
cors({
origin: configs.AllowedOrigins,
credentials: true,
}),
);

app.use(
"/api",
trpcExpress.createExpressMiddleware({
router: appRouter,
createContext: () => ({ session: null }),
}),
"/api",
trpcExpress.createExpressMiddleware({
router: appRouter,
createContext: () => ({ session: null }),
}),
);

const verifyVolcanoSetup = async () => {
try {
await k8sApi.listClusterCustomObject({
group: "batch.volcano.sh",
version: "v1alpha1",
plural: "jobs",
});
return true;
} catch (error) {
console.error("Volcano verification failed:", error);
return false;
}
try {
await k8sApi.listClusterCustomObject({
group: "batch.volcano.sh",
version: "v1alpha1",
plural: "jobs",
});
return true;
} catch (error) {
console.error("Volcano verification failed:", error);
return false;
}
};

export const server = app.listen(configs.Port, async () => {
const volcanoReady = await verifyVolcanoSetup();
if (volcanoReady) {
console.log(
`Server running on port ${configs.Port} with Volcano support`,
);
} else {
console.error("Server started but Volcano support is not available");
}
const volcanoReady = await verifyVolcanoSetup();
if (volcanoReady) {
console.log(`Server running on port ${configs.Port} with Volcano support`);
} else {
console.error("Server started but Volcano support is not available");
}
});
14 changes: 10 additions & 4 deletions packages/trpc/server/utils/configs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { config as dotenvConfig } from "dotenv";

export interface Configs {
Port: number;
Env: string;
Port: number;
Env: string;
AllowedOrigins: string[];
}

dotenvConfig({ path: "secrets.env" });

export const configs: Configs = {
Port: parseInt(process.env.PORT || "3001"),
Env: process.env.NODE_ENV || "development",
Port: parseInt(process.env.PORT || "3001"),
Env: process.env.NODE_ENV || "development",
AllowedOrigins: process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(",")
.map((o) => o.trim())
.filter(Boolean)
: ["http://localhost:3000", "http://localhost:5173"],
Comment thread
krsatyamthakur-droid marked this conversation as resolved.
};