Skip to content
Oxide
Esc
navigateopen⌘Jpreview

Server Entry

Handle a request in your server entry, or skip it and let static files take over.

Every request hits this file first. The default path is src/server.ts. Export a fetch that takes the request and returns a response. On preset: "celld" the runtime also passes Worker env and ctx — the same pair actions read with useEnv() / useFetchCtx().

export default {
  
function fetch(request: Request, env?: {
    SECRET?: string;
}, ctx?: {
    waitUntil?(p: Promise<unknown>): void;
}): Response | undefined
fetch
(
request: Requestrequest: Request,
env: {
    SECRET?: string;
} | undefined
env
?: { SECRET?: string | undefinedSECRET?: string },
ctx: {
    waitUntil?(p: Promise<unknown>): void;
} | undefined
ctx
?: { waitUntil?(p: Promise<unknown>): voidwaitUntil?(p: Promise<unknown>p: interface Promise<T>
Represents the completion of an asynchronous operation
Promise
<unknown>): void },
) { if (new var URL: new (url: string | URL, base?: string | URL) => URL
The **`URL`** interface is used to parse, construct, normalize, and encode URLs. It works by providing properties which allow you to easily read and modify the components of a URL. [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL)
URL
(request: Requestrequest.Request.url: string
The **`url`** read-only property of the Request interface contains the URL of the request. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/url)
url
).URL.pathname: string
The **`pathname`** property of the URL interface represents a location in a hierarchical structure. It is a string constructed from a list of path segments, each of which is prefixed by a / character. [MDN Reference](https://developer.mozilla.org/docs/Web/API/URL/pathname)
pathname
=== "/api/ok") {
ctx: {
    waitUntil?(p: Promise<unknown>): void;
} | undefined
ctx
?.waitUntil?(p: Promise<unknown>): voidwaitUntil?.(var Promise: PromiseConstructor
Represents the completion of an asynchronous operation
Promise
.PromiseConstructor.resolve(): Promise<void> (+2 overloads)
Creates a new resolved promise.
@returnsA resolved promise.
resolve
());
return new var Response: new (body?: BodyInit | null, init?: ResponseInit) => Response
The **`Response`** interface of the Fetch API represents the response to a request. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response)
Response
(
env: {
    SECRET?: string;
} | undefined
env
?.SECRET?: string | undefinedSECRET ?? "ok");
} }, };

If fetch returns nothing, oxidejs keeps going. With a page in the project, that means a matching static file. Missing files fall back to index.html only for navigations (Sec-Fetch-Dest: document or Accept: text/html). A fetch for /missing.js is still 404.

public/ is copied next to the client on preset: "fetch". Hashed assets get Cache-Control: immutable. index.html is no-cache. Without a page, the build is only the server bundle - there is nothing to fall through to.

Named exports such as scheduled and queue stay on the celld wrapper. Spread them yourself if you replace fetch.

To serve typed RPC from this file, set up a tacho router and pass it to handle(). See the Tacho quickstart.

Was this page helpful?