From 5e5e4ae746a9c5a1f412693a27c7e1c6c4dcacdf Mon Sep 17 00:00:00 2001 From: Billy Date: Sat, 25 Jan 2025 11:01:27 +0530 Subject: [PATCH] feat: Update base url --- package.json | 4 ++-- server/api/index.js | 6 +++++- src/services/adventOfCode.ts | 11 +++++++---- src/services/codeExecution.ts | 4 +++- src/services/constants.ts | 6 +++--- src/services/performanceAnalysis.ts | 18 ++++++++---------- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 00a4ec0..40ac1f9 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,11 @@ "version": "0.5.0", "type": "module", "scripts": { - "dev": "concurrently \"node server.js\" \"vite\"", + "dev": "vite", "build": "vite build", "lint": "eslint .", "preview": "vite preview", - "start": "node api/index.js" + "start": "concurrently \"node server.js\" \"vite\"" }, "dependencies": { "@google/generative-ai": "^0.21.0", diff --git a/server/api/index.js b/server/api/index.js index ab08874..a907f4d 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -5,7 +5,11 @@ const vm = require("node:vm"); const app = express(); const PORT = 3001; -app.use(cors()); +app.use( + cors({ + origin: "*", + }) +); app.use(express.json()); const genAI = new GoogleGenerativeAI(process.env.API_KEY); diff --git a/src/services/adventOfCode.ts b/src/services/adventOfCode.ts index fa610d6..babde70 100644 --- a/src/services/adventOfCode.ts +++ b/src/services/adventOfCode.ts @@ -28,10 +28,13 @@ export async function fetchPuzzle( day: number ): Promise { try { - const response = await fetchWithTimeout(`${BASE_URL}/${year}/${day}`, { - headers: HEADERS, - credentials: "omit", - }); + const response = await fetchWithTimeout( + `${BASE_URL}/puzzle/${year}/${day}`, + { + headers: HEADERS, + credentials: "omit", + } + ); if (!response.ok) { const error: FetchError = { diff --git a/src/services/codeExecution.ts b/src/services/codeExecution.ts index 87c7967..f9a045c 100644 --- a/src/services/codeExecution.ts +++ b/src/services/codeExecution.ts @@ -1,3 +1,5 @@ +import { BASE_URL } from "./constants"; + interface ExecutionResult { output: string[]; runtime: number | null; @@ -6,7 +8,7 @@ interface ExecutionResult { export async function executeCode(code: string): Promise { try { - const response = await fetch("http://localhost:3001/api/execute", { + const response = await fetch(`${BASE_URL}/execute`, { method: "POST", headers: { "Content-Type": "application/json", diff --git a/src/services/constants.ts b/src/services/constants.ts index 0fec446..2eed82a 100644 --- a/src/services/constants.ts +++ b/src/services/constants.ts @@ -1,5 +1,5 @@ -export const BASE_URL = 'http://localhost:3001/api/puzzle'; +export const BASE_URL = "http://aoc-flhj.onrender.com"; export const HEADERS = { - 'Accept': 'application/json', -}; \ No newline at end of file + Accept: "application/json", +}; diff --git a/src/services/performanceAnalysis.ts b/src/services/performanceAnalysis.ts index fc43fa2..17ce8fa 100644 --- a/src/services/performanceAnalysis.ts +++ b/src/services/performanceAnalysis.ts @@ -1,4 +1,5 @@ import { fetchWithTimeout } from "../utils/fetch"; +import { BASE_URL } from "./constants"; interface AnalysisResponse { timeComplexity: string; @@ -7,16 +8,13 @@ interface AnalysisResponse { export async function analyzeCode(code: string): Promise { try { - const response = await fetchWithTimeout( - "http://localhost:3001/api/analyze", - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ code }), - } - ); + const response = await fetchWithTimeout(`${BASE_URL}/analyze`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ code }), + }); if (!response.ok) { throw new Error("Analysis failed");