32backend.use("*", cors()) // Allow all origins for demo purposes
33backend.use("*", secureHeaders())
34// CSRF protection can be added if using cookie-based sessions, might be overkill for this API demo if using token auth
35// app.use("*", csrf());
3654// Error handler - Unwrap Hono errors to see original error details
55backend.onError((err, c) => {
56console.error("API Error:", err)
57// Check if it's an HTTPError from Hono, otherwise it's an internal error
58if (err && typeof err === 'object' && 'getResponse' in err && typeof err.getResponse === 'function') {
477// The payload for updateSupplierBillWithAIData expects a full BillScanResponse structure.
478// This might need a dedicated service method if the payload is different.
479console.warn(`PUT /api/bills/:billId - Manual bill update logic might need a dedicated service method. Reusing updateSupplierBillWithAIData for now if payload matches.`)
480const updatedBill = await db.updateSupplierBillWithAIData(billId, payload as BillScanResponse, userId) // Casting payload, ensure it's compatible
481
stockAppinventoryApp.http.tsx2 matches
5// import {serveStatic} from "https://esm.sh/hono@4.4.6/deno" // Unused and causing error
6import {readFile, parseProject} from "https://esm.town/v/std/utils@85-main/index.ts" // Val Town utils
7import backendRoutes from "./backend/api.ts"
8const app = new Hono()
9949596app.route("/api", backendRoutes)
9798
bluesky-thinkup-tributewatcher.tsx2 matches
1import { email } from "https://esm.town/v/std/email?v=13";
2import { sqlite } from "https://esm.town/v/std/sqlite2?v=1";
3import { AtpAgent, AtpSessionData, AtpSessionEvent } from "npm:@atproto/api";
4import diff from "npm:fast-diff@1.3.0";
52627// Supports up to 5,000 (100*50) follows, stopping there to try
28// and avoid rate limits. These APIs have pretty low limits, sound off here
29// https://github.com/bluesky-social/atproto/discussions/3356
30outerLoop: for (let i = 0; i < 20; i++) {
bluesky-thinkup-tributeREADME.md2 matches
18I was an avid user of [ThinkUp](https://www.thinkupapp.com/), a tool that connected to Twitter and sent me a daily email with profile updates from all the people I followed. I found it useful in work and for fun. Maybe one of my friends switched jobs or changed their username to something goofy or political. I want to know! In the distant past Facebook would include profile updates in the newsfeed: why not that for Twitter? ThinkUp did some other cool stuff, like providing full archives of Tweets in a more convenient format than Twitter did themselves.
1920But Twitter [is bad now](https://macwright.com/2025/03/04/twitter-eol) and ThinkUp [shut down in 2016](https://www.thinkupapp.com/) because [the APIs that they were relying on from Twitter, Facebook, and Instagram were all locked down and limited](https://medium.com/@anildash/the-end-of-thinkup-e600bc46cc56). How disappointing.
2122But there's a new social network in town, [Bluesky](https://bsky.app/), and it's ~~impossible~~ somewhat more difficult to corrupt and enshittify than those networks were, and it comes with a pretty good, if sometimes weird API that gives you access to everything you need.
2324Could you build some of ThinkUp on Bluesky? Yes. This is it.
sa_pmtindex.html2 matches
126// Get the base URL to handle any path prefixes
127const baseUrl = new URL(window.location.href).origin;
128const apiUrl = `${baseUrl}/api/enhance`;
129
130const response = await fetch(apiUrl, {
131method: 'POST',
132headers: {
22app.get("/frontend/*", (c) => serveFile(c.req.path, import.meta.url));
2324// API endpoint to enhance prompts
25app.post("/api/enhance", async (c) => {
26try {
27const body = await c.req.json().catch(() => ({}));
68});
69} catch (openaiError) {
70console.error("OpenAI API error:", openaiError);
71return c.json({
72error: "OpenAI service error",
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"