Skip to content

Commit

Permalink
Use withActors instead of use
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Sep 23, 2024
1 parent 8f1f600 commit 932b12e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/actors/hono/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { MiddlewareHandler } from "@hono/hono";
import type { ActorRuntime } from "../mod.ts";
import { ActorRuntime } from "../mod.ts";
import type { ActorConstructor } from "../runtime.ts";

/**
* Adds middleware to the Hono server that routes requests to actors.
* the default base path is `/actors`.
*/
export const useActors = (
rt: ActorRuntime,
export const withActors = (
rtOrActors: ActorRuntime | Array<ActorConstructor>,
basePath = "/actors",
): MiddlewareHandler => {
const rt = Array.isArray(rtOrActors)
? new ActorRuntime(rtOrActors)
: rtOrActors;
return async (ctx, next) => {
if (!ctx.req.path.startsWith(basePath)) {
return next();
Expand Down

0 comments on commit 932b12e

Please sign in to comment.