Skip to content

Commit

Permalink
Add good defaults
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 7f40997 commit 1e50fdf
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/actors/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,35 @@ type Promisify<Actor> = {
: Actor[key];
};

const ACTORS_SERVER_URL: string | undefined = Deno.env.get(
"DENO_ACTORS_SERVER_URL",
);
const DEPLOYMENT: string | undefined = Deno.env.get("DENO_DEPLOYMENT_ID");
/**
* utilities to create and manage actors.
*/
export const actors = {
proxy: <TInstance extends Actor>(
c: ProxyOptions<TInstance>,
actor: ActorConstructor<TInstance> | string,
server = ACTORS_SERVER_URL,
): { id: (id: string) => Promisify<TInstance> } => {
return {
id: (id: string): Promisify<TInstance> => {
return new Proxy<Promisify<TInstance>>({} as Promisify<TInstance>, {
get: (_, prop) => {
return async (...args: unknown[]) => {
const resp = await fetch(
`${c.server}/actors/${
typeof c.actor === "string" ? c.actor : c.actor.name
`${server}/actors/${
typeof actor === "string" ? actor : actor.name
}/invoke/${String(prop)}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
[ACTOR_ID_HEADER_NAME]: id,
...DEPLOYMENT
? { ["x-deno-deployment-id"]: DEPLOYMENT }
: {},
},
body: JSON.stringify({
args,
Expand Down

0 comments on commit 1e50fdf

Please sign in to comment.