{"id":50866508,"url":"https://github.com/jpbaking/url-shortener","last_synced_at":"2026-06-15T02:01:57.154Z","repository":{"id":364828827,"uuid":"1269378920","full_name":"jpbaking/url-shortener","owner":"jpbaking","description":"Dockerized self-hosted URL shortener: shorten links, optional expiry, click counts, and 302 redirects. React + Express + Prisma + PostgreSQL behind Nginx.","archived":false,"fork":false,"pushed_at":"2026-06-14T17:13:29.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-14T18:14:42.529Z","etag":null,"topics":["docker-compose","express","nginx","playwright","postgresql","prisma","react","self-hosted","typescript","url-shortener"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpbaking.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-06-14T16:33:52.000Z","updated_at":"2026-06-14T17:13:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jpbaking/url-shortener","commit_stats":null,"previous_names":["jpbaking/url-shortener"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/jpbaking/url-shortener","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpbaking%2Furl-shortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpbaking%2Furl-shortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpbaking%2Furl-shortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpbaking%2Furl-shortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpbaking","download_url":"https://codeload.github.com/jpbaking/url-shortener/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpbaking%2Furl-shortener/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34344440,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","express","nginx","playwright","postgresql","prisma","react","self-hosted","typescript","url-shortener"],"created_at":"2026-06-15T02:01:56.548Z","updated_at":"2026-06-15T02:01:57.142Z","avatar_url":"https://github.com/jpbaking.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener\n\nA self-hosted URL shortener. Paste a long URL into the web UI and get a short link; visiting the short link issues a `302` redirect to the original URL.\n\nThe app runs across **two domains backed by one service** (both are configurable via `.env`; the defaults below are examples):\n\n- **`short.url`** (`SHORT_DOMAIN`) — a React SPA where users shorten URLs.\n- **`s.url`** (`S_DOMAIN`) — short-link resolution; every request proxies straight to the backend redirect handler.\n\n## Stack\n\n| Layer        | Technology                          |\n|--------------|-------------------------------------|\n| Frontend     | React + Vite (TypeScript)           |\n| Backend      | Express + Prisma (TypeScript)       |\n| Database     | PostgreSQL                          |\n| Reverse proxy| Nginx                               |\n| Orchestration| Docker Compose                      |\n| E2E tests    | Playwright                          |\n\nOnly Nginx (port `80`) is exposed; the backend and PostgreSQL stay on the internal Docker network.\n\n## Quick start\n\nRequires Docker and Docker Compose.\n\n```bash\n# 1. Configure environment\ncp .env.example .env\n# edit .env — set your domains and (optionally) S_SCHEME=https\n\n# 2. Bring up the full stack\ndocker compose up --build\n```\n\nTo browse the app locally, map your configured domains to your loopback address (they aren't real DNS names):\n\n```\n# /etc/hosts  — replace with your SHORT_DOMAIN and S_DOMAIN values\n127.0.0.1 short.url s.url\n```\n\nThen open `http://\u003cSHORT_DOMAIN\u003e` (e.g. \u003chttp://short.url\u003e) to shorten a URL.\n\n\u003e **Production — public (Cloudflare Tunnel):** No DNS `A` record or open inbound port needed. Run a `cloudflared` tunnel and point it at `localhost:80`. Cloudflare terminates TLS automatically; set `S_SCHEME=https` in `.env`. Because cloudflared is the TCP peer of Nginx, client IPs arrive via `X-Forwarded-For` — the Nginx config handles this automatically.\n\u003e\n\u003e **Production — internal (nginx-proxy-manager):** Create local DNS records for `SHORT_DOMAIN` and `S_DOMAIN` pointing to your server. Configure NPM to proxy both hostnames to `localhost:80` (or the Docker host IP on port `80`). NPM handles TLS (Let's Encrypt or self-signed). Set `S_SCHEME=https` once TLS is in place. Client IPs are forwarded via `X-Forwarded-For` and resolved correctly by Nginx.\n\n## Configuration\n\nThe root `.env` (copied from `.env.example`) supplies five variables consumed by Compose:\n\n| Variable            | Description                                              | Default      |\n|---------------------|----------------------------------------------------------|--------------|\n| `POSTGRES_DB`       | Database name                                            | —            |\n| `POSTGRES_PASSWORD` | PostgreSQL superuser password                           | —            |\n| `SHORT_DOMAIN`      | Hostname for the SPA                                     | `short.url`  |\n| `S_DOMAIN`          | Hostname for short-link resolution                      | `s.url`      |\n| `S_SCHEME`          | Scheme for short links shown to users (`http`/`https`)  | `http`       |\n\nCompose derives `REDIRECT_DOMAIN` as `${S_SCHEME}://${S_DOMAIN}` and injects it, along with `DATABASE_URL`, into the backend. Data persists in the `pg_data` named volume — removing it drops all shortened URLs.\n\n## API\n\n### `POST /api/shorten`\n\nRequest body:\n\n```json\n{\n  \"longUrl\": \"https://example.com/some/very/long/path\",\n  \"expiryValue\": 7,\n  \"expiryUnit\": \"days\"\n}\n```\n\n- `longUrl` (required) — must start with `http://` or `https://`, max 2048 characters.\n- `expiryValue` / `expiryUnit` (optional) — omit for a link that never expires. Units: `minutes`, `hours`, `days`, `weeks`, `months`.\n\nResponse (`201` for a new link, `200` for a dedup hit):\n\n```json\n{\n  \"shortUrl\": \"http://s.url/aB3x9Z\",\n  \"expiresAt\": \"2026-06-22T12:00:00.000Z\"\n}\n```\n\nSubmitting the same URL from the same IP within one hour of a prior submission returns `429 Too Many Requests` with a `Retry-After` header. After the window clears, a new short code is always created.\n\n### `GET /:code`\n\nResolves a short code: `302` redirect to the original URL, `410 Gone` if the link has expired, or `400` for a malformed code. Each successful resolution increments a click counter (fire-and-forget — a counter failure never blocks the redirect).\n\nShort codes are random base62 strings, 6–16 characters; length grows automatically on collision.\n\n## Common commands\n\n```bash\ndocker compose up --build        # build + start the full stack\ndocker compose down              # stop (keep data)\ndocker compose down -v           # stop and wipe the database volume\ndocker compose logs -f backend   # tail logs (nginx | backend | postgres)\n```\n\n## Testing\n\nA Playwright E2E suite runs against the live stack (it does not mock the backend or database). With the stack up:\n\n```bash\ndocker compose --profile test run --rm playwright\n```\n\nThe Playwright container resolves `short.url` / `s.url` via Docker network aliases, so no `/etc/hosts` edits are needed for tests. Reports are written to `playwright/playwright-report/` and `playwright/test-results/`.\n\n## Project layout\n\n```\n.\n├── backend/      Express + Prisma API (shorten + redirect handlers, DB schema)\n├── frontend/     React + Vite SPA\n├── nginx/        Reverse-proxy config (templated per domain via envsubst)\n├── playwright/   End-to-end test suite\n└── docker-compose.yml\n```\n\nEach directory carries an `AGENTS.md` documenting its contracts and workflow.\n\n## License\n\nReleased under the [BSD Zero-Clause License](LICENSE) (`0BSD`) — effectively public domain. Use, copy, modify, and distribute it for any purpose, with **no attribution required** and **no warranty**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpbaking%2Furl-shortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpbaking%2Furl-shortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpbaking%2Furl-shortener/lists"}