Skip to content

Commit

Permalink
pr requests
Browse files Browse the repository at this point in the history
  • Loading branch information
microchipgnu committed Jan 22, 2025
1 parent 2c414b1 commit 63316c1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import dotenv from "dotenv";
import isPortReachable from "is-port-reachable";

import { startApiServer } from "../services/proxy";
import { startUIServer } from "../services/server";
import { getDeployedUrl } from "../utils/deployed-url";
import { validateEnv } from "../utils/env";
import { validateAndParseOpenApiSpec } from "../utils/openapi";
Expand Down Expand Up @@ -99,7 +99,7 @@ export const devCommand = new Command()
const { port, serverPort } = await setupPorts(options);

API_CONFIG.serverPort = serverPort;
const server = await startApiServer(API_CONFIG);
const server = await startUIServer(API_CONFIG);

const deployedUrl = getDeployedUrl(port);
if (!deployedUrl) {
Expand Down
33 changes: 1 addition & 32 deletions src/services/proxy.ts → src/services/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ApiConfig {
serverPort: number;
}

export async function startApiServer(
export async function startUIServer(
apiConfig: ApiConfig,
): Promise<ReturnType<typeof express.application.listen>> {
const app = express();
Expand Down Expand Up @@ -64,37 +64,6 @@ export async function startApiServer(
}
});

// Handle chat requests
app.post("/api/v1/chat", async (req, res) => {
try {
const response = await fetch(apiConfig.url, {
method: "POST",
headers: {
Authorization: `Bearer ${apiConfig.key}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(req.body),
});

const data = await response.text();

res.status(response.status);
response.headers.forEach((value, key) => {
// Skip content-encoding to avoid compression issues
if (key.toLowerCase() !== "content-encoding") {
res.setHeader(key, value);
}
});
res.send(data);
} catch (error) {
res.status(500).json({
error: "Internal server error",
message: error instanceof Error ? error.message : "Unknown error",
});
}
});

return new Promise<ReturnType<typeof app.listen>>((resolve, reject) => {
try {
const server = app.listen(apiConfig.serverPort, () => {
Expand Down

0 comments on commit 63316c1

Please sign in to comment.