Skip to content

Commit 578fe8d

Browse files
committed
tenant api
1 parent 990d487 commit 578fe8d

27 files changed

+3652
-0
lines changed

apps/self-hosted/DEPLOYMENT.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,68 @@ docker-compose build --no-cache
390390
└────────────────────────┘
391391
```
392392

393+
---
394+
395+
## Managed Hosting by Ecency
396+
397+
Don't want to manage your own infrastructure? Let Ecency host your blog.
398+
399+
### Pricing
400+
401+
| Plan | Price | Features |
402+
|------|-------|----------|
403+
| **Standard** | 1 HBD/month | Custom subdomain, SSL, CDN, 99.9% uptime |
404+
| **Pro** | 3 HBD/month | Custom domain, priority support, analytics |
405+
406+
### How to Get Started
407+
408+
1. **Visit** [ecency.com/blog-hosting](https://ecency.com/blog-hosting)
409+
2. **Connect** your Hive wallet
410+
3. **Configure** your blog (username, theme, features)
411+
4. **Pay** via HBD transfer to `@ecency.hosting`
412+
5. **Go live** instantly!
413+
414+
### Custom Domain Setup
415+
416+
For custom domains, add a CNAME record:
417+
418+
```
419+
Type: CNAME
420+
Name: blog (or @ for root domain)
421+
Value: YOUR-BLOG-ID.blogs.ecency.com
422+
TTL: 3600
423+
```
424+
425+
**Example:**
426+
- Your domain: `myblog.com`
427+
- CNAME: `myblog.com``alice.blogs.ecency.com`
428+
429+
### Payment Memo Format
430+
431+
When paying via HBD transfer:
432+
433+
```
434+
To: @ecency.hosting
435+
Amount: 1.000 HBD
436+
Memo: blog:YOUR_HIVE_USERNAME
437+
```
438+
439+
For renewals, use the same memo format. Subscriptions auto-renew if balance is available.
440+
441+
### Managed Hosting API
442+
443+
Programmatic access for advanced users:
444+
445+
```bash
446+
# Check subscription status
447+
curl https://api.ecency.com/blog-hosting/status/YOUR_USERNAME
448+
449+
# Get config
450+
curl https://api.ecency.com/blog-hosting/config/YOUR_USERNAME
451+
```
452+
453+
---
454+
393455
## Support
394456

395457
- GitHub Issues: https://github.com/ecency/vision-next/issues
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Ecency Managed Hosting Platform - Environment Variables
2+
3+
# =============================================================================
4+
# Domain Configuration
5+
# =============================================================================
6+
BASE_DOMAIN=blogs.ecency.com
7+
8+
# =============================================================================
9+
# SSL / Let's Encrypt
10+
# =============================================================================
11+
12+
13+
# Cloudflare API (for wildcard SSL)
14+
CF_API_EMAIL=[email protected]
15+
CF_API_KEY=your-cloudflare-api-key
16+
17+
# =============================================================================
18+
# Database
19+
# =============================================================================
20+
POSTGRES_PASSWORD=your-secure-password-here
21+
22+
# =============================================================================
23+
# Security
24+
# =============================================================================
25+
JWT_SECRET=your-jwt-secret-here
26+
27+
# Traefik dashboard auth (generate with: htpasswd -nb admin password)
28+
TRAEFIK_DASHBOARD_AUTH=admin:$$apr1$$xyz...
29+
30+
# =============================================================================
31+
# Hive Blockchain
32+
# =============================================================================
33+
HIVE_API_URL=https://api.hive.blog
34+
35+
# Account to receive HBD payments
36+
PAYMENT_ACCOUNT=ecency.hosting
37+
38+
# Monthly subscription price in HBD
39+
MONTHLY_PRICE_HBD=1.000
40+
41+
# Pro plan upgrade price in HBD
42+
PRO_UPGRADE_PRICE_HBD=3.000

apps/self-hosted/hosting/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Ecency Managed Hosting Platform
2+
3+
Multi-tenant hosting infrastructure for Ecency self-hosted blogs.
4+
5+
## Architecture Overview
6+
7+
```
8+
┌─────────────────────────────────────┐
9+
│ DNS (Cloudflare) │
10+
│ *.blogs.ecency.com → Load Balancer │
11+
│ Custom domains → CNAME validation │
12+
└──────────────────┬──────────────────┘
13+
14+
┌──────────────────▼──────────────────┐
15+
│ Load Balancer (Traefik) │
16+
│ - SSL termination (Let's Encrypt) │
17+
│ - Dynamic routing by hostname │
18+
│ - Rate limiting │
19+
└──────────────────┬──────────────────┘
20+
21+
┌───────────────────────────────────────┼───────────────────────────────────────┐
22+
│ │ │
23+
┌─────────▼─────────┐ ┌───────────▼───────────┐ ┌────────────▼────────────┐
24+
│ Blog Instance │ │ Blog Instance │ │ Hosting API │
25+
│ (nginx + SPA) │ │ (nginx + SPA) │ │ (Node.js/Deno) │
26+
│ │ │ │ │ │
27+
│ alice.blogs.ec... │ │ bob.blogs.ecency... │ │ api.ecency.com/hosting │
28+
│ config: alice.json│ │ config: bob.json │ │ │
29+
└───────────────────┘ └───────────────────────┘ └────────────┬────────────┘
30+
31+
┌──────────────────┼──────────────────┐
32+
│ │ │
33+
┌────────▼────────┐ ┌───────▼───────┐ ┌────────▼────────┐
34+
│ Config DB │ │ HBD Payment │ │ Domain Verify │
35+
│ (PostgreSQL) │ │ Listener │ │ Service │
36+
│ │ │ │ │ │
37+
│ - Tenant configs│ │ - Watch txs │ │ - CNAME check │
38+
│ - Subscriptions │ │ - Auto-renew │ │ - SSL provision │
39+
│ - Custom domains│ │ - Receipts │ │ │
40+
└─────────────────┘ └───────────────┘ └─────────────────┘
41+
```
42+
43+
## Components
44+
45+
### 1. Traefik (Edge Router)
46+
- Handles all incoming traffic
47+
- Dynamic routing based on hostname
48+
- Automatic SSL via Let's Encrypt
49+
- Wildcard cert for `*.blogs.ecency.com`
50+
51+
### 2. Blog Instances
52+
- Shared static SPA assets
53+
- Per-tenant config.json
54+
- Served via nginx
55+
56+
### 3. Hosting API
57+
- Tenant management (CRUD)
58+
- Subscription handling
59+
- Config generation
60+
- Domain verification
61+
62+
### 4. HBD Payment Listener
63+
- Monitors Hive blockchain for payments
64+
- Activates/renews subscriptions
65+
- Sends notifications
66+
67+
## Deployment Models
68+
69+
### Model A: Shared Container (Recommended for Scale)
70+
All tenants share a single nginx container with dynamic config routing.
71+
72+
```
73+
┌─────────────────────────────────────┐
74+
│ Nginx Container │
75+
│ /usr/share/nginx/html/ │
76+
│ ├── index.html (shared SPA) │
77+
│ ├── static/ (shared assets) │
78+
│ └── configs/ │
79+
│ ├── alice.json │
80+
│ ├── bob.json │
81+
│ └── carol.json │
82+
│ │
83+
│ Config routing via $host header │
84+
└─────────────────────────────────────┘
85+
```
86+
87+
### Model B: Container Per Tenant (Isolation)
88+
Each tenant gets their own container. Higher resource usage but better isolation.
89+
90+
```
91+
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
92+
│ Alice │ │ Bob │ │ Carol │
93+
│ Container │ │ Container │ │ Container │
94+
└─────────────┘ └─────────────┘ └─────────────┘
95+
```
96+
97+
## Files
98+
99+
- `docker-compose.yml` - Full hosting stack
100+
- `traefik/` - Traefik configuration
101+
- `nginx/` - Multi-tenant nginx config
102+
- `api/` - Hosting management API
103+
- `scripts/` - Utility scripts
104+
105+
## Quick Start
106+
107+
```bash
108+
# Start the hosting platform
109+
docker-compose up -d
110+
111+
# Add a new tenant
112+
./scripts/add-tenant.sh alice
113+
114+
# Check tenant status
115+
./scripts/tenant-status.sh alice
116+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Ecency Hosting API - Dockerfile
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install dependencies
7+
COPY package.json ./
8+
RUN npm install
9+
10+
# Copy source
11+
COPY . .
12+
13+
# Build TypeScript
14+
RUN npm run build
15+
16+
# Production image
17+
FROM node:20-alpine
18+
19+
WORKDIR /app
20+
21+
# Copy built files
22+
COPY --from=builder /app/dist ./dist
23+
COPY --from=builder /app/package.json ./
24+
COPY --from=builder /app/node_modules ./node_modules
25+
26+
# Create configs directory
27+
RUN mkdir -p /app/configs
28+
29+
# Set environment
30+
ENV NODE_ENV=production
31+
ENV PORT=3001
32+
ENV CONFIG_DIR=/app/configs
33+
34+
EXPOSE 3001
35+
36+
# Health check
37+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \
38+
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1
39+
40+
CMD ["node", "dist/index.js"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Ecency Hosting Payment Listener - Dockerfile
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
# Install dependencies
7+
COPY package.json ./
8+
RUN npm install
9+
10+
# Copy source
11+
COPY . .
12+
13+
# Build TypeScript
14+
RUN npm run build
15+
16+
# Production image
17+
FROM node:20-alpine
18+
19+
WORKDIR /app
20+
21+
# Copy built files
22+
COPY --from=builder /app/dist ./dist
23+
COPY --from=builder /app/package.json ./
24+
COPY --from=builder /app/node_modules ./node_modules
25+
26+
# Create configs directory
27+
RUN mkdir -p /app/configs
28+
29+
# Set environment
30+
ENV NODE_ENV=production
31+
ENV CONFIG_DIR=/app/configs
32+
33+
# No exposed port - this is a background worker
34+
35+
CMD ["node", "dist/payment-listener.js"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@ecency/hosting-api",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"scripts": {
6+
"dev": "tsx watch src/index.ts",
7+
"build": "tsc",
8+
"start": "node dist/index.js",
9+
"start:listener": "node dist/payment-listener.js",
10+
"db:migrate": "tsx src/db/migrate.ts"
11+
},
12+
"dependencies": {
13+
"@hiveio/dhive": "^1.3.0",
14+
"hono": "^4.4.0",
15+
"pg": "^8.12.0",
16+
"redis": "^4.6.0",
17+
"zod": "^3.23.0",
18+
"date-fns": "^3.6.0",
19+
"nanoid": "^5.0.0"
20+
},
21+
"devDependencies": {
22+
"@types/node": "^20.14.0",
23+
"@types/pg": "^8.11.0",
24+
"tsx": "^4.15.0",
25+
"typescript": "^5.5.0"
26+
}
27+
}

0 commit comments

Comments
 (0)