Skip to content

Commit

Permalink
feat: Update base url
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jan 25, 2025
1 parent 46ee600 commit 5e5e4ae
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion server/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/services/adventOfCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ export async function fetchPuzzle(
day: number
): Promise<PuzzleData> {
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 = {
Expand Down
4 changes: 3 additions & 1 deletion src/services/codeExecution.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BASE_URL } from "./constants";

interface ExecutionResult {
output: string[];
runtime: number | null;
Expand All @@ -6,7 +8,7 @@ interface ExecutionResult {

export async function executeCode(code: string): Promise<ExecutionResult> {
try {
const response = await fetch("http://localhost:3001/api/execute", {
const response = await fetch(`${BASE_URL}/execute`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
6 changes: 3 additions & 3 deletions src/services/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
};
Accept: "application/json",
};
18 changes: 8 additions & 10 deletions src/services/performanceAnalysis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetchWithTimeout } from "../utils/fetch";
import { BASE_URL } from "./constants";

interface AnalysisResponse {
timeComplexity: string;
Expand All @@ -7,16 +8,13 @@ interface AnalysisResponse {

export async function analyzeCode(code: string): Promise<AnalysisResponse> {
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");
Expand Down

0 comments on commit 5e5e4ae

Please sign in to comment.