Web endpoints
A Function with web serves its fetch handler at a *.modal.run URL. Modal starts containers as requests arrive, like it does for calls.
Proxy auth keeps strangers out
Section titled “Proxy auth keeps strangers out”A web endpoint answers anyone unless it requires proxy auth. Then Modal’s proxy checks each request’s token before it reaches a container:
Serve fetch
Section titled “Serve fetch”import * as Modal from "@alchemy.run/modal";import * as Effect from "effect/Effect";import * as HttpServerResponse from "effect/http/HttpServerResponse";import { Inference } from "./Inference.ts";
export default class Site extends Modal.Function<Site>()( "Site", { main: import.meta.url, app: Inference, web: true }, Effect.gen(function* () { return { fetch: Effect.succeed(HttpServerResponse.text("hello from Modal")) }; }),) {}The URL is the url attribute.
Pick the label in its URL
Section titled “Pick the label in its URL”{ main: import.meta.url, app: Inference, web: { label: "site" } }The URL becomes https://<workspace>--site.modal.run.
Require proxy auth
Section titled “Require proxy auth”{ main: import.meta.url, app: Inference, web: { requiresProxyAuth: true } }Callers then send the Modal-Key and Modal-Secret headers of a Modal.WebhookToken.
Call it from a Worker
Section titled “Call it from a Worker”const site = yield* Modal.FetchServer(Site);const response = yield* site.fetch(HttpClientRequest.get("/"));FetchServer adds the proxy auth headers for you.