Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Nanoo CDN Architecture

This document shows how the system works and how requests move through it, maybe in the future there will be improve

## How the worker processes a request

This diagram shows the steps the Worker takes for each new request. It also shows how the cache helps to make it faster.

```mermaid
graph TD
A[User Request] --> B{Method GET/HEAD?}
B -- No --> C[Return 405 Method Not Allowed]
B -- Yes --> D[Generate cacheKey]

D --> E{Cache HIT?}
E -- Yes --> F[Return Cached Response]
E -- No --> G[Clean the URL Path]

G --> H{List Bucket Request?}
H -- Yes --> I[Return 404/Forbidden]
H -- No --> J[Sign Request for Security]

J --> K{Range Header Present?}
K -- Yes --> L[Fetch from B2 with Retries]
K -- No --> M[Fetch from B2]

L --> N{Response OK?}
M --> N

N -- Yes --> O[Save to Edge Cache]
O --> P[Return File to User]
N -- No --> Q[Return Error Response]
```

## Step by step request flow

This diagram shows how the User, Cloudflare, and backblaze B2 talk to each other.

```mermaid
sequenceDiagram
participant U as User
participant E as Cloudflare Edge Cache
participant W as Worker (src/index.js)
participant B as Backblaze B2 (Origin)

U->>E: GET /assets/logo.png
alt Cache HIT
E-->>U: Return file (very fast)
else Cache MISS
E->>W: Forward Request
W->>W: Clean Path & Headers
W->>W: Sign Request for Security
W->>B: Send Request to B2
B-->>W: 200 OK / 206 Partial Content
W->>E: Save file to Cache
W-->>U: Return File
end
```

## Project Parts

- **`src/index.js`**: **Main controller**
- **`src/lib/signer.js`**: **Security handler**
- **`src/lib/cache.js`**: **Speed manager**
- **`src/lib/utils.js`**: **Helper tools**
22 changes: 13 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [2.0.0] - 2026-05-18

### Fixed

- Updated README to use current `npm create cloudflare` and `npx wrangler deploy` commands ([@harrisonratcliffe](https://github.com/harrisonratcliffe/))
- Fixed comments around RCLONE_DOWNLOAD in wrangler.toml.template ([@jingyuanliang](https://github.com/jingyuanliang/))
- Do not sign conditional request headers, since they are not always passed upstream by Cloudflare.
- Fixed `RCLONE_DOWNLOAD` option so that bucket name can be passed in the path.
### Added
- Integration Cloudflare cache API for 300x faster TTFB (3ms-9ms on HIT)
- Refactore codebase to `src/` and `src/lib/` for better maintain
- Add `ARCHITECTURE.md` with Mermaid diagram
- add Log prefix `[CACHE]`, `[SIGN]`, and `[B2]`

### Changed
- Move main entry point to `src/index.js`
- Enhance header filtering and path sanitization logic

### Fixed
- Resolve `TypeError` when modification headers for cache API
- Update README to use current `pnpm create cloudflare` and `pnpm dlx wrangler deploy` command
- Fix `RCLONE_DOWNLOAD` option so that bucket name can be passed in the path

- Bumped direct dependencies to current versions, moved `wrangler` to `devDependencies`.
- Removed user-agent check for rcloneDownload - this allows other clients to use B2 friendly URLs.

## [1.2.0] - 2024-10-09

Expand Down
73 changes: 14 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,21 @@
# Nanoo CDN
# Nanoo CDN v2.0.0

A high-performance CDN edge proxy for nanoo ecosystems it uses Cloudflare Workers to serve files securely from a private Backblaze B2 bucket.
High performance, secure edge proxy using cloudflare workers and backblaze B2.
zero egress costs, 3ms-9ms TTFB, and AWS SigV4 security

This project is based on the cloudflare-b2 implementation.
## Quick start

## Architecture
1. **Install:** `pnpm install`
2. **Setup:** Create `.dev.vars` from `.dev.vars.templates` and add your `B2_APPLICATION_KEY`
3. **Dev:** `pnpm dlx wrangler dev` (testing at `http://localhost:8787`)
4. **Deploy:** `pnpm dlx wrangler deploy`

This service works as a bridge between users and private storage.
## Documentation
- **[Architecture & flow](ARCHITECTURE.md)**: Deep dive to the request lifecycle and mermaid diagrams
- **[Changelog](CHANGELOG.md)**: Track the latest updates and v2.0 improvements

Client -> Cloudflare Worker -> Backblaze B2

The B2 bucket is private. The Worker signs each request using AWS Signature Version 4 and fetches the file from the B2 endpoint. This prevents unauthorized access to your files.

### Benefits
- No Egress Cost: Moving data from Backblaze B2 to Cloudflare is free because of the Bandwidth Alliance.
- Edge Caching: Files are cached at Cloudflare edge nodes. This makes delivery faster and reduces costs.
- Security: Directory listing is disabled. The Worker uses a restricted key that can only read from the nanoo-assets bucket.

<!-- ## Repository Structure

Files in the B2 bucket are organized into these folders ():

- brands/: logos, banners, and icons for Nanoo Cloud.
- ui/: images and icons for the user interface.
- public/: general files like fonts and global styles. -->

## Getting Started

### Prerequisites
- pnpm installed.
- A Cloudflare account with the domain nanoolabs.dev
- A Backblaze B2 account with a private bucket.

### Local Development
1. Install dependencies:
```bash
pnpm install
```
2. Create a .dev.vars file from the .dev.vars.template and add your B2_APPLICATION_KEY.
3. Start the development server:
```bash
pnpm dlx wrangler dev
```

### Deployment
Deployment is done with Wrangler. You must save your secrets in Cloudflare:

```bash
# Save your B2 Secret Key (run this once)
pnpm dlx wrangler secret put B2_APPLICATION_KEY
```

# Deploy to production
```bash
pnpm dlx wrangler deploy
```

## Credits

This project uses the following resources:
- [cloudflare-b2](https://github.com/backblaze-b2-samples/cloudflare-b2) by Backblaze for the original implementation.
- Cloudflare and Backblaze for providing the bandwidth alliance.
## Credit
Based on the [cloudflare-b2](https://github.com/backblaze-b2-samples/cloudflare-b2) implementation by backblaze

## License
This project is licensed under the MIT License and Apache License 2.0.
Licensed under MIT and Apache 2.0
17 changes: 17 additions & 0 deletions cors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"corsRuleName": "allow-nanoo-labs",
"allowedOrigins": [
"https://nanoo.biz.id",
"https://api.nanoo.biz.id",
"https://me.nanoolabs.dev",
"https://docs.nanoolabs.dev",
"https://nanoolabs.dev",
"https://me.nanoolabs.dev"
],
"allowedHeaders": ["*"],
"allowedOperations": ["s3_get", "s3_head"],
"exposeHeaders": ["ETag", "Content-Type", "Content-Length"],
"maxAgeSeconds": 3600
}
]
13 changes: 13 additions & 0 deletions cors.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"corsRuleName": "allow-your-domain",
"allowedOrigins": [
"https://your-domain.com",
"https://api.your-domain.com"
],
"allowedHeaders": ["*"],
"allowedOperations": ["s3_get", "s3_head"],
"exposeHeaders": ["ETag", "Content-Type", "Content-Length"],
"maxAgeSeconds": 3600
}
]
Loading
Loading