# Obsidian Cloud

> Obsidian Cloud is a hosting platform for websites, web apps and APIs, similar to Vercel. Connect a GitHub repository (or upload a .zip), and every push to the production branch builds and deploys automatically, with HTTPS on a free subdomain or your own domain. This page is written for both people and AI coding assistants: follow it exactly when preparing a project for Obsidian Cloud.

Dashboard: https://web.obcloud.in
This document (plain text): https://web.obcloud.in/llms.txt
Config file schema: https://web.obcloud.in/schema/obsidian.json

## Instructions for AI assistants

If the user says their hosting provider is Obsidian Cloud:

1. Work out the project type from the files (see "Project types"). Do not invent settings that are not documented here.
2. Web servers must listen on `0.0.0.0` and the port in the `PORT` environment variable (it is `3000`). Never hard-code another port.
3. Put build and routing settings in `obsidian.json` in the repository root (see "obsidian.json"). An existing `vercel.json` also works without changes.
4. Never put secrets (passwords, API keys, tokens) in `obsidian.json` or in the code. Tell the user to add them under Project → Environment Variables in the dashboard.
5. Databases are only reachable from apps running on Obsidian Cloud, through `DATABASE_URL` / `REDIS_URL`. A static site cannot use a database.
6. After changes, the user only needs to `git push`; the deployment starts automatically.

## Project types

Pick a framework when creating the project. The defaults below are used unless `obsidian.json` or the dashboard overrides them.

| Type | Detected by / used for | Install | Build | Output / start |
|---|---|---|---|---|
| Static (Vite, React, Vue, Svelte, Astro) | `package.json` with a build script | `npm install` | `npm run build` | serves `dist` (Create React App: `build`) |
| Plain HTML | no `package.json` | — | — | serves the files as they are |
| Next.js, Nuxt, Remix, SvelteKit, NestJS, Express | Node.js server | `npm install` | `npm run build` (if any) | `npm start` (Nuxt: `node .output/server/index.mjs`, SvelteKit: `node build`) |
| Python (FastAPI, Flask, Django, custom) | `requirements.txt` | `pip install -r requirements.txt` | — | FastAPI: `uvicorn main:app --host 0.0.0.0 --port $PORT`, Flask: `gunicorn -b 0.0.0.0:$PORT app:app` |
| PHP (Laravel, Symfony, CodeIgniter, custom) | `composer.json` | `composer install --no-dev` | — | FrankenPHP serving `public/` on `$PORT` |
| Docker (Go, Rust, Bun, anything) | `Dockerfile` | — | `docker build` | the image's `CMD`; listen on port 3000 |
| WordPress, Pterodactyl Panel | 1-click apps | — | — | managed by the platform |

Runtimes: Node.js 22, Python 3.12, PHP 8.3 (FrankenPHP).

### Rules for apps (Node.js, Python, PHP, Docker)

- Listen on `0.0.0.0:$PORT` (`PORT` is `3000`). Example (Express): `app.listen(process.env.PORT || 3000, "0.0.0.0")`.
- `NODE_ENV` is `production`.
- The file system is not permanent between deployments. Store data in a database, not in local files.
- CPU and memory come from the project's resource settings, within the plan's limits.
- Background jobs: use **Workers** (a long-running command, for example a Discord bot or a queue consumer) and **Cron Jobs** (a command on a 5-field cron schedule, run inside the app, 120 second limit).

### Static sites

- Everything in the output folder is served over HTTPS.
- Unknown paths fall back to `index.html`, so single-page apps (React Router, Vue Router) work without extra settings.
- Files under `/assets/` are cached for 30 days (Vite puts hashed files there).
- A static site runs in the visitor's browser. It cannot connect to a database or keep secrets. To hide an API address or key, proxy it with a rewrite (see "Hide a backend URL").

## Environment variables

- Add them in the dashboard: Project → Environment Variables. They are available during the build and at runtime.
- Changes apply on the next deployment.
- In front-end code, only variables your framework exposes at build time are visible (Vite: names starting with `VITE_`). Anything in front-end code is public.

## Databases

Create them under Project → Databases: PostgreSQL 16, MySQL (MariaDB 11) or Redis 7.

- Turning on "Add to Environment Variables" sets `DATABASE_URL` (PostgreSQL, MySQL) or `REDIS_URL` (Redis).
- Hosts look like `ob-postgres`, `ob-mariadb` or `ob-redis-…`. They only resolve inside Obsidian Cloud. Connecting from your computer does not work, by design.
- Browse tables, run SQL and take `.sql` backups in **Obsidian DB Studio** (the "Open in Studio" button). Backups run daily and the last 7 are kept.
- Database storage and backups count toward the plan's disk limit. Each Redis reserves 64 MB of memory.

Example (Node.js, PostgreSQL):

```js
import pg from "pg"
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
```

Example (Prisma): `datasource db { provider = "postgresql" url = env("DATABASE_URL") }`

## Domains

- Every project gets a free subdomain: `<project>.obclouds.in`.
- Add your own domain under Project → Domains and create the DNS records shown there. The HTTPS certificate is issued automatically.

## obsidian.json

An optional file in the repository root. It is read on every deployment. Settings in the file win over the dashboard for that deployment.

- If `obsidian.json` is missing, `vercel.json` is used (same format). If both exist, `obsidian.json` wins.
- If the file has an error, the deployment stops with a clear message and the live site is not changed.
- Vercel-only settings (`functions`, `crons`, `regions`, `routes`, `images`, …) are ignored with a warning in the deploy log.
- Unknown settings are errors, with a "did you mean" hint.

### Full example

```json
{
  "$schema": "https://web.obcloud.in/schema/obsidian.json",
  "installCommand": "npm ci",
  "buildCommand": "npm run build",
  "outputDirectory": "dist",
  "cleanUrls": true,
  "trailingSlash": false,
  "redirects": [
    { "source": "/old-blog/:slug", "destination": "/blog/:slug", "permanent": true }
  ],
  "rewrites": [
    { "source": "/api/:path*", "destination": "https://api.example.com/:path*" },
    { "source": "/docs/:page*", "destination": "/docs.html" }
  ],
  "headers": [
    {
      "source": "/(.*)",
      "headers": [{ "key": "X-Frame-Options", "value": "DENY" }]
    }
  ]
}
```

### Settings

| Setting | Type | What it does |
|---|---|---|
| `installCommand` | string | Command that installs dependencies |
| `buildCommand` | string | Command that builds the project |
| `outputDirectory` | string | Folder with the built static files (static sites) |
| `cleanUrls` | boolean | Serve `/about.html` at `/about` and redirect `.html` URLs to the clean version |
| `trailingSlash` | boolean | `true`: redirect `/about` to `/about/`. `false`: redirect `/about/` to `/about` |
| `redirects` | list | Send visitors to another URL |
| `rewrites` | list | Serve another path, or proxy to another server, without changing the URL |
| `headers` | list | Add response headers |

### Path patterns (`source`)

- `/blog/:slug` matches one segment (`/blog/hello`).
- `/api/:path*` matches zero or more segments (`/api`, `/api/a/b`).
- `/api/:path+` matches one or more segments.
- `/user/:id(\\d+)` matches a custom regular expression.
- `/(.*)` matches everything; use `$1` in the destination.
- Use the same names in `destination` (`/new/:slug`, `https://api.example.com/:path*`).

### Redirects

```json
{ "source": "/old", "destination": "/new", "permanent": true }
```

`permanent: true` (default) returns 308, `false` returns 307. Or set `"statusCode"`: 301, 302, 303, 307 or 308. The query string is kept. The destination can be a path or a full URL.

### Rewrites

- To a path (`"destination": "/index.html"`): on static sites the rewrite applies only when no file matches the URL. In apps the app receives the new path.
- To a URL (`"destination": "https://…"`): the request is proxied to that server. See below.

### Hide a backend URL (proxy)

Use this when a website calls an API or bot backend hosted somewhere else (another VPS, a game panel, a Discord bot dashboard). The browser only sees your domain. The backend's IP address and port never appear in the browser's network tab.

```json
{
  "rewrites": [
    { "source": "/api/:path*", "destination": "http://203.0.113.10:8080/:path*" }
  ]
}
```

Then call `fetch("/api/stats")` from the front end instead of the backend's address. This also removes CORS problems, because the front end and the API are on the same domain.

- The backend receives the visitor's IP in `X-Forwarded-For` and `X-Real-IP`, and your domain in `X-Forwarded-Host`.
- WebSockets work. Requests time out after 120 seconds, and uploads are limited to 32 MB.
- The backend must be a public address. Private and internal addresses (`localhost`, `10.x`, `192.168.x`, `127.x`, …) are rejected.
- The backend's domain name is resolved during the deployment. If its IP address changes later, redeploy.
- This hides the address from the browser. The backend is still reachable on the internet if someone finds its address in another way. To lock it down completely, configure the backend's firewall to accept only requests from Obsidian Cloud.

### Headers

```json
{
  "source": "/assets/(.*)",
  "headers": [{ "key": "Cache-Control", "value": "public, max-age=31536000, immutable" }]
}
```

When several rules set the same header for a path, the last matching rule wins. Header values can't contain double quotes, backslashes or `$`.

### Not supported

`has` / `missing` conditions are skipped with a warning. Serverless `functions`, `crons`, `regions` and `routes` are not available in the file. Use apps, Workers and Cron Jobs in the dashboard instead.

## Examples

### Vite / React single-page app

Nothing is required: SPA routing works by default. Optional `obsidian.json`:

```json
{ "buildCommand": "npm run build", "outputDirectory": "dist" }
```

### Website plus a backend hosted elsewhere

```json
{ "rewrites": [{ "source": "/api/:path*", "destination": "https://bot.example.com/api/:path*" }] }
```

### Express API

```js
import express from "express"
const app = express()
app.get("/health", (_req, res) => res.send("ok"))
app.listen(process.env.PORT || 3000, "0.0.0.0")
```

`package.json` needs `"start": "node index.js"`.

### FastAPI

`requirements.txt` with `fastapi` and `uvicorn`, and `main.py` defining `app`. The default start command is `uvicorn main:app --host 0.0.0.0 --port $PORT`.

### Dockerfile

```dockerfile
FROM golang:1.23-alpine AS build
WORKDIR /src
COPY . .
RUN go build -o /app .

FROM alpine:3.20
COPY --from=build /app /app
ENV PORT=3000
CMD ["/app"]
```

The program must listen on port 3000.

## Automate with AI (MCP)

Obsidian Cloud has an MCP server, so AI assistants (Claude, Cursor, …) can create projects, deploy, read logs and set environment variables.

- URL: `https://web.obcloud.in/api/mcp`
- Auth: `Authorization: Bearer <token>`. Create a token on the "MCP & Tokens" page of the dashboard (https://web.obcloud.in/tokens). Treat it like a password.
- Tools: `list_projects`, `create_project`, `deploy_files`, `redeploy_project`, `get_deployment_logs`, `set_env_vars`.

## Troubleshooting

| Problem | Fix |
|---|---|
| "the app exited right after starting" | The app must listen on `0.0.0.0:$PORT`. Check the deployment logs. |
| "output folder 'dist' not found" | Set `outputDirectory` (or the Output Directory setting) to the folder your build creates. |
| Page refresh shows the wrong page on a SPA | Remove rewrites that send everything to another file; the default fallback already serves `index.html`. |
| Can't connect to the database from my computer | Expected. Use Obsidian DB Studio, or connect from an app on Obsidian Cloud. |
| Proxy rewrite rejected as "private or internal address" | The backend must have a public IP address. |
| Changes to environment variables don't apply | Redeploy: variables are applied on the next deployment. |
