Skip to content

amirparsadd/r1ec-edge-hono

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

r1ec-edge-hono

A minimal example showing how to deploy a Hono web app on ArvanCloud Edge Computing.

This project demonstrates how to build and bundle a Hono app and run it in Arvan's edge function environment using the r1ec CLI.


🌐 Features

  • ✅ Lightweight API using Hono (a super-fast edge framework)
  • 🚀 Deployable on ArvanCloud Edge Compute
  • 🔁 Portable to other edge platforms like Cloudflare Workers, Deno Deploy, Bun, etc.

🛠 Setup

1. Clone and install dependencies

git clone https://github.com/amirparsadd/r1ec-edge-hono.git
cd r1ec-edge-hono
npm install

2. Develop the API

The main logic lives in src/index.ts:

import { Hono } from 'hono'
import { basicAuth } from 'hono/basic-auth'
import { cors } from 'hono/cors'

export const app = new Hono()

app.use(cors())

app.get('/', (c) => c.json({ message: 'Hello World' }))

app.get(
  '/secret',
  basicAuth({
    username: 'admin',
    password: 'admin',
  }),
  (c) => {
    return c.text('This is a secret!')
  }
)

// Make it compatible with R1Cloud Edge
export default {
  async fetch(request: Request) {
    return app.fetch(request)
  }
}

3. Build for deployment

npm run build

This will generate a bundled dist/index.js using esbuild, ready for edge deployment.

4. Deploy with ArvanCloud CLI

First, install and login to the CLI:

npm install -g r1ec
r1ec login -m YOUR_MACHINE_KEY

Then deploy:

r1ec deploy test -f dist/index.js

You'll receive a public edge URL in the panel.


🧪 Example API Call

curl https://test.amirparsab9.arvanedge.ir/

Response:

{ "message":"Hello World" }

📁 Project Structure

r1c-edge-hono
├── src/
│   └── index.ts       # Hono app source code
├── dist/
│   └── index.js      # Bundled deployable output
├── package.json
├── README.md
└── LICENSE.md

🧠 How It Works

ArvanCloud Edge expects a JavaScript file that exports a fetch(request) handler. Hono supports this natively:

// Make it compatible with R1EC
export default {
  async fetch(request: Request) {
    return app.fetch(request)
  }
}

This wrapper allows Arvan to treat the Hono app as an Edge Function.


📚 References


📄 License

MIT

About

An example on how to use HonoJs for R1EC

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published