2122- Frontend: HTML, JavaScript with Tailwind CSS for styling
23- Backend: TypeScript API using Hono framework and OpenAI integration
24- Deployed on Val Town
25
12import QuickActions from "./QuickActions.tsx"
13import {User, CreateUserPayload} from "../../shared/types.ts"
14// import * as apiClient from "../apiClient.ts"; // This was removed
1516const API_BASE_URL = "/api" // Ensure this is defined
1718const App: FunctionComponent = () => {
52try {
53// Direct fetch for users
54const response = await fetch(`/api/users`)
55if (!response.ok) {
56let errorData
60errorData = {error: "Request failed", message: response.statusText || "Unknown error"}
61}
62console.error("API Error (fetchUsers):", errorData, "Status:", response.status)
63throw new Error(errorData.message || errorData.error || `Failed to fetch users: ${response.status}`)
64}
122}
123// Direct fetch to add user
124const response = await fetch(`${API_BASE_URL}/users`, {
125method: "POST",
126headers: {
Launchingofproductindex.js6 matches
144sendButton.textContent = 'Sending...';
145
146// Send message to API
147const response = await fetch('/api/messages', {
148method: 'POST',
149headers: {
189async function fetchNewMessages() {
190try {
191const response = await fetch('/api/messages');
192const result = await response.json();
193
336submitButton.textContent = 'Posting...';
337
338// Send job to API
339const response = await fetch('/api/jobs', {
340method: 'POST',
341headers: {
432async function fetchJobs() {
433try {
434const response = await fetch('/api/jobs');
435const result = await response.json();
436
Launchingofproductindex.ts27 matches
10addJobPosting
11} from "./database/queries.ts";
12import { ApiResponse, ChatMessage, JobPosting } from "../shared/types.ts";
1314// Initialize the Hono app
52});
5354// === Chat Message API Endpoints ===
5556// API endpoint to get chat messages
57app.get("/api/messages", async c => {
58try {
59const messages = await getChatMessages();
60const response: ApiResponse<ChatMessage[]> = {
61success: true,
62data: messages
65} catch (error) {
66console.error("Error fetching messages:", error);
67const response: ApiResponse<null> = {
68success: false,
69error: "Failed to fetch messages"
73});
7475// API endpoint to add a new chat message
76app.post("/api/messages", async c => {
77try {
78const body = await c.req.json();
81// Validate input
82if (!username || !message) {
83const response: ApiResponse<null> = {
84success: false,
85error: "Username and message are required"
91const newMessage = await addChatMessage(username, message);
92
93const response: ApiResponse<ChatMessage> = {
94success: true,
95data: newMessage
98} catch (error) {
99console.error("Error adding message:", error);
100const response: ApiResponse<null> = {
101success: false,
102error: "Failed to add message"
106});
107108// === Job Posting API Endpoints ===
109110// API endpoint to get all job postings
111app.get("/api/jobs", async c => {
112try {
113const jobs = await getJobPostings();
114const response: ApiResponse<JobPosting[]> = {
115success: true,
116data: jobs
119} catch (error) {
120console.error("Error fetching job postings:", error);
121const response: ApiResponse<null> = {
122success: false,
123error: "Failed to fetch job postings"
127});
128129// API endpoint to get a single job posting
130app.get("/api/jobs/:id", async c => {
131try {
132const id = parseInt(c.req.param("id"));
133
134if (isNaN(id)) {
135const response: ApiResponse<null> = {
136success: false,
137error: "Invalid job ID"
143
144if (!job) {
145const response: ApiResponse<null> = {
146success: false,
147error: "Job posting not found"
150}
151
152const response: ApiResponse<JobPosting> = {
153success: true,
154data: job
157} catch (error) {
158console.error("Error fetching job posting:", error);
159const response: ApiResponse<null> = {
160success: false,
161error: "Failed to fetch job posting"
165});
166167// API endpoint to add a new job posting
168app.post("/api/jobs", async c => {
169try {
170const body = await c.req.json();
181// Validate required fields
182if (!title || !company || !description || !location || !contact_email || !posted_by) {
183const response: ApiResponse<null> = {
184success: false,
185error: "Missing required fields"
199);
200
201const response: ApiResponse<JobPosting> = {
202success: true,
203data: newJob
206} catch (error) {
207console.error("Error adding job posting:", error);
208const response: ApiResponse<null> = {
209success: false,
210error: "Failed to add job posting"
Launchingofproducttypes.ts1 match
20}
2122export interface ApiResponse<T> {
23success: boolean;
24data?: T;
YouthCareerToolkitindex.ts2 matches
34});
3536// API endpoint to generate content
37app.post("/api/generate", async (c) => {
38try {
39const data = await c.req.json() as GenerateRequest;
tosChatPage.tsx7 matches
25const fetchChatRooms = async () => {
26try {
27const response = await fetch("/api/chat/rooms", {
28headers: {
29"Authorization": `Bearer ${token}`
58const fetchOnlineUsers = async () => {
59try {
60const response = await fetch("/api/users/online", {
61headers: {
62"Authorization": `Bearer ${token}`
89
90try {
91const response = await fetch(`/api/chat/rooms/${activeChatRoom.id}/messages`, {
92headers: {
93"Authorization": `Bearer ${token}`
101
102// Join the chat room
103await fetch(`/api/chat/rooms/${activeChatRoom.id}/join`, {
104method: "POST",
105headers: {
144
145try {
146const response = await fetch(`/api/chat/direct/${selectedUser.id}`, {
147headers: {
148"Authorization": `Bearer ${token}`
203
204try {
205const response = await fetch(`/api/chat/rooms/${activeChatRoom.id}/messages`, {
206method: "POST",
207headers: {
235
236try {
237const response = await fetch(`/api/chat/direct/${selectedUser.id}`, {
238method: "POST",
239headers: {
tosPostItem.tsx1 match
45try {
46const token = localStorage.getItem("tos_token");
47const response = await fetch(`/api/posts/${post.id}/comments`, {
48headers: {
49"Authorization": `Bearer ${token}`
tosFeedPage.tsx5 matches
26try {
27const currentOffset = reset ? 0 : offset;
28const response = await fetch(`/api/posts?limit=${limit}&offset=${currentOffset}`, {
29headers: {
30"Authorization": `Bearer ${token}`
74
75try {
76const response = await fetch("/api/posts", {
77method: "POST",
78headers: {
107const handleLike = async (postId: number) => {
108try {
109const response = await fetch(`/api/posts/${postId}/like`, {
110method: "POST",
111headers: {
133const handleComment = async (postId: number, content: string) => {
134try {
135const response = await fetch(`/api/posts/${postId}/comments`, {
136method: "POST",
137headers: {
166const handleDelete = async (postId: number) => {
167try {
168const response = await fetch(`/api/posts/${postId}`, {
169method: "DELETE",
170headers: {
untitled-8850arena-blocks.html7 matches
237238try {
239// Log start of API request
240console.log('🔄 Starting API request to Are.na...');
241console.time('API Request');
242
243// Fetch data from Are.na API
244const response = await fetch('https://api.are.na/v2/search/blocks?sort=updated_at');
245
246// Log response received
247console.log(`✅ Response received with status: ${response.status}`);
248console.timeEnd('API Request');
249
250if (!response.ok) {
251throw new Error(`API responded with status: ${response.status}`);
252}
253