* feat: Convert to a webhooks api model! feat: Update readme with new api docs and images and logo feat: reoptimize jpgs and add comments to all images for credit feat: Add database backend implementations Todo is to update the readme feat: use memory storage for endpoints feat: add logging to rest api and remove ctrl override feat: remove keyboard monitor delete the discord api from direct reference * feat: webhook sending with retries and backoff Also some great readme changes * feat: add a web based dev mode! * feat: better error handling for webhook endopoints * feat: remove verbose logs * feat: add docs for local dev * feat: remove complex webhook stuff config file with endpoints listed instead * feat: update logo * feat: set endpoint and remove rest api * fix: check for negative config numbers * feat: remove timestamps from webhook Use Date header instead * feat: refactor to using one endpoint with env vars * feat: change logging to be one rolling log With a max line size of 10k lines * feat: move config to toml, keep api in env var * feat: use .env files for managing env vars * fix: remove log files from dev * fix: unblock web monitor thread * feat: merge into a monorepo with noisebridge-status
3.6 KiB
NoiseBell Status API
A simple status API built with Next.js and Prisma, designed to report whether a noisebridge is open or closed.
API Endpoints
GET /api/status
Retrieves the current status of the service.
Response:
200 OK: Returns the current status200 OK: Returns{"status": "closed"}if no status records exist
Example Response:
{
"status": "OPEN",
"createdAt": "2024-01-15T10:30:00.000Z"
}
POST /api/status
Updates the current status of the service.
Headers Required:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
Request Body:
{
"status": "open" | "closed"
}
Response:
201 Created: Status successfully updated400 Bad Request: Invalid JSON, missing status field, or invalid status value401 Unauthorized: Missing or invalid API key500 Internal Server Error: Server configuration error
Example Request:
curl -X POST http://localhost:3000/api/status \
-H "Authorization: Bearer your-api-key-here" \
-H "Content-Type: application/json" \
-d '{"status": "open"}'
Example Response:
{
"status": "OPEN",
"createdAt": "2024-01-15T10:30:00.000Z"
}
Environment Variables
Local Development
Create a .env.local file in the root directory with the following variables:
DATABASE_URL="postgresql://username:password@localhost:5432/your_database"
API_KEY="your-secret-api-key-here"
Production with Vercel
If you're deploying to Vercel, you can manage environment variables using Vercel CLI:
-
Link your project to Vercel:
pnpx vercel env link -
Pull environment variables from Vercel:
pnpx vercel env pull .env.local -
Set environment variables in Vercel dashboard:
- Go to your project in the Vercel dashboard
- Navigate to Settings → Environment Variables
- Add the required variables:
DATABASE_URL: Your PostgreSQL connection stringAPI_KEY: Your secret API key
Required Environment Variables
DATABASE_URL: PostgreSQL connection stringAPI_KEY: Secret key for API authentication
Database Schema
The API uses a PostgreSQL database with the following schema:
-- StatusType enum
CREATE TYPE "StatusType" AS ENUM ('OPEN', 'CLOSED');
-- Status table
CREATE TABLE "statuses" (
"id" SERIAL PRIMARY KEY,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"status" "StatusType" NOT NULL DEFAULT 'OPEN'
);
Development
Prerequisites
- Node.js 18+
- PostgreSQL database
- pnpm (recommended) or npm
Installation
-
Clone the repository
-
Install dependencies:
pnpm install -
Set up your environment variables in
.env.local -
Run database migrations:
pnpm prisma db push -
Start the development server:
pnpm dev
The API will be available at http://localhost:3000/api/status
Database Management
Generate Prisma client:
pnpm prisma generate
View database in Prisma Studio:
pnpm prisma studio
Error Codes
| Status Code | Description |
|---|---|
| 200 | Success - Status retrieved |
| 201 | Success - Status created/updated |
| 400 | Bad Request - Invalid input |
| 401 | Unauthorized - Invalid or missing API key |
| 500 | Internal Server Error - Server configuration issue |
Status Values
The API accepts lowercase values in requests but stores them as uppercase enum values:
"open"→"OPEN""closed"→"CLOSED"
License
This project is open source and available under the MIT License.