building out back and front end apis

This commit is contained in:
KS Jannette
2026-02-11 12:00:00 -05:00
parent 0a2eaeb537
commit bf907c900d
5 changed files with 1546 additions and 4 deletions

View File

@@ -1 +1,10 @@
import dotenv from 'dotenv';
dotenv.config({ path: '.secrets' });
const config = {
port: process.env.PORT || 3001,
openaiApiKey: process.env.OPENAI_API_KEY,
};
export default config;

1504
backend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1 +1,22 @@
import { Router } from 'express';
import { readFile } from 'fs/promises';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const router = Router();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const DATA_PATH = join(__dirname, '..', 'data', 'notes.json');
router.get('/', async (req, res) => {
try {
const raw = await readFile(DATA_PATH, 'utf-8');
const notes = JSON.parse(raw);
res.json(notes);
} catch (err) {
res.status(500).json({ error: 'Failed to load notes' });
}
});
export default router;

View File

@@ -1,8 +1,8 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import type { Sticky } from '../types/types';
const fetchStickies = async (): Promise<Sticky[]> => {
const fetchStickies = async () => { const response = await fetch('http://localhost:3001/api/notes');
const response = await fetch('https://<backend-url>/v1/stickies');
if (!response.ok) { if (!response.ok) {
throw new Error('Network response was not ok'); throw new Error('Network response was not ok');
} }
@@ -18,7 +18,7 @@ const fetchStickies = async () => {
if (isLoading) return <div>Loading...</div>; if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>; if (error) return <div>Error: {error.message}</div>;
return <div>{data?.map((sticky: any) => <div key={sticky.id}>{sticky.text}</div>)}</div>; return <div>{data?.map((sticky) => <div key={sticky.id}>{sticky.text}</div>)}</div>;
}; };
export default Stickies; export default Stickies;

View File

@@ -0,0 +1,8 @@
export type Sticky = {
id: string;
text: string;
x: number;
y: number;
author: string;
color: string;
};