Skip to content

Commit

Permalink
Dispatch complex fetch event
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiancook committed Dec 31, 2023
1 parent d07a6e8 commit cb5b345
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/worker/service-worker/configure/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {importConfiguration} from "./import";
import {join} from "node:path";
import { Config } from "./types";
import {ok} from "../../../is";
import {DurableEventData} from "../../../data";

function isURL(value: string) {
try {
Expand Down Expand Up @@ -55,6 +56,9 @@ try {
const event = getOption("event");
const service = getOption("service");
const entrypoint = getOption("entrypoint");
const request = getOption("request");
const method = getOption("method");
const body = getOption("body");

const configured = await importConfiguration(configUrl, {
noStringifyConfig: argv.includes("--no-stringify-config"),
Expand All @@ -65,9 +69,19 @@ try {
if (event) {
const named = await configured.getService(service);
const dispatch = await named.activated;
const dispatching: DurableEventData = {
type: event
}
if (event === "fetch" && request) {
dispatching.request = {
url: event,
method,
body
};
}
await dispatch({
type: "dispatch",
dispatch: event,
dispatch: dispatching,
entrypoint,
virtual: true
})
Expand Down

0 comments on commit cb5b345

Please sign in to comment.