noisebell/noisebell-status
Jet Pham dff2e96947
Update Main to monorepo structure (#5)
* 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
2025-08-05 00:33:41 -05:00
..
prisma Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
public Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
src Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
.gitignore Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
components.json Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
eslint.config.mjs Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
next.config.ts Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
package.json Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
pnpm-lock.yaml Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
pnpm-workspace.yaml Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
postcss.config.mjs Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
README.md Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00
tsconfig.json Update Main to monorepo structure (#5) 2025-08-05 00:33:41 -05:00

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 status
  • 200 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 updated
  • 400 Bad Request: Invalid JSON, missing status field, or invalid status value
  • 401 Unauthorized: Missing or invalid API key
  • 500 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:

  1. Link your project to Vercel:

    pnpx vercel env link
    
  2. Pull environment variables from Vercel:

    pnpx vercel env pull .env.local
    
  3. 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 string
      • API_KEY: Your secret API key

Required Environment Variables

  • DATABASE_URL: PostgreSQL connection string
  • API_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

  1. Clone the repository

  2. Install dependencies:

    pnpm install
    
  3. Set up your environment variables in .env.local

  4. Run database migrations:

    pnpm prisma db push
    
  5. 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.