Router
Instantiates a server framework-agnostic router for Porto.
Usage
import { Router, Route } from 'porto/server'
const router = Router()
.route('/merchant', Route.merchant({/* ... */})
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
Routes
Route | Description |
---|---|
Route.merchant | Route for Merchant RPC (call sponsoring, subscriptions, etc). |
Route.auth 🚧 | Route for a user authentication service. |
Route.relay 🚧 | Route for self-hosted Relay RPC. |
Frameworks
Cloudflare Workers
import { env } from 'cloudflare:workers'
import { Router, Route } from 'porto/server'
export default Router({ basePath: '/porto' })
.route('/merchant', Route.merchant({ /* ... */ })
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
) satisfies ExportedHandler<Env>
Next.js
app/porto/[[...routes]]/route.ts
import { Router, Route } from 'porto/server'
const porto = Router({ basePath: '/porto' })
.route('/merchant', Route.merchant({ /* ... */ })
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
)
export const GET = porto.fetch
export const OPTIONS = porto.fetch
export const POST = porto.fetch
Hono
import { Hono } from 'hono'
import { Router, Route } from 'porto/server'
const app = new Hono()
const porto = Router()
.route('/merchant', Route.merchant({ /* ... */ })
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
)
app.route('/porto', porto.hono)
export default app
Bun
import { Router, Route } from 'porto/server'
const porto = Router({ basePath: '/porto' })
.route('/merchant', Route.merchant({ /* ... */ })
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
)
Bun.serve(porto)
Deno
import { Router, Route } from 'porto/server'
const porto = Router({ basePath: '/porto' })
.route('/merchant', Route.merchant({ /* ... */ })
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
)
Deno.serve(porto.fetch)
Express
import express from 'express'
import { Router, Route } from 'porto/server'
const app = express()
const porto = Router({ basePath: '/porto' })
.route('/merchant', Route.merchant({ /* ... */ })
// .route('/auth', Route.auth({/* ... */}) 🚧
// .route('/rpc', Route.relay({/* ... */}) 🚧
)
app.use(porto.listener)
app.listen(3000)
Other Frameworks
If you would like to see an example of your framework here, please open a discussion and we'll add it.