Something went wrong. Try again.
write Deno web servers with Vite
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import type { ErrorPayload, HotPayload } from 'vite';
/** marks a response body as JSON-encoded {@link SerializedError} */export const ERROR_HEADER = 'x-dromi-error';
/** request error in Vite's overlay format */export type SerializedError = ErrorPayload['err'];
/** Vite hot channel payload, relayed in either direction */export type HotMessage = { type: 'hot'; payload: HotPayload };
/** first message sent to the Deno process */export type InitMessage = { type: 'init'; /** absolute path to the server entrypoint */ entry: string; /** URL of `vite/module-runner`, matching the `vite` that runs the dev server */ moduleRunner: string;};
/** Deno process log for Vite's logger */export type LogMessage = { type: 'log'; level: 'error' | 'info'; message: string;};
/** sent by the Deno process once its server is listening */export type ReadyMessage = { type: 'ready'; /** port of the server, on `127.0.0.1` */ port: number;};
/** requests a process restart for an unaccepted HMR update */export type RestartMessage = { type: 'restart' };
/** worker module runner request to Vite's hot channel */export type InvokeMessage = { type: 'invoke'; /** request id, unique across workers */ id: string; payload: HotPayload;};
/** response to an {@link InvokeMessage}, with the same `id` */export type ResultMessage = { type: 'result'; id: string; result: { result: unknown } | { error: unknown };};
/** message sent from the Vite host to the Deno process */export type HostMessage = HotMessage | InitMessage | ResultMessage;
/** message sent from the Deno process to the Vite host */export type RunnerMessage = HotMessage | InvokeMessage | LogMessage | ReadyMessage | RestartMessage;
/** `BroadcastChannel` shared by the Deno main thread and its workers */export const WORKER_CHANNEL = 'dromi:worker';
/** worker requests and host responses relayed by the main thread over {@link WORKER_CHANNEL} */export type WorkerChannelMessage = InvokeMessage | ResultMessage;