Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fae70f6
initial commit
timreichen Jul 10, 2024
4666cfa
update
timreichen Jul 10, 2024
9171850
update
timreichen Jul 10, 2024
ef4e382
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Jul 23, 2024
36ae7c7
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Jul 31, 2024
773b5b1
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 15, 2024
d1daec1
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 23, 2024
b88e008
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Sep 5, 2024
9dcdb98
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Sep 14, 2024
ac61af1
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Sep 20, 2024
060adc8
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Oct 1, 2024
35ba966
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Oct 4, 2024
10c1c40
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Oct 12, 2024
4f7e521
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Nov 10, 2024
bfb315b
update
timreichen Nov 10, 2024
eb4251e
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Dec 12, 2024
d7d0410
add req deprecation
timreichen Dec 12, 2024
d2b951c
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Dec 12, 2024
5ffccb7
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Dec 24, 2024
ef59ca9
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Feb 10, 2025
85e769a
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Feb 18, 2025
ad02cdb
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Mar 5, 2025
2544ef8
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Mar 5, 2025
e0de83b
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Mar 9, 2025
822317f
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Apr 25, 2025
990bcea
Merge branch 'denoland:main' into rename-FreshContext-req-to-request
timreichen Apr 28, 2025
ccdf6b6
update
timreichen Apr 28, 2025
8409664
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen May 7, 2025
71c0922
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen May 7, 2025
00e7319
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen May 14, 2025
89d1f19
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen May 27, 2025
d23aa4e
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen May 27, 2025
e341f43
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Jun 6, 2025
054e568
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Jul 29, 2025
3fd8142
update
timreichen Jul 29, 2025
0e5102e
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 7, 2025
e36edb1
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 7, 2025
75ba023
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 8, 2025
e8f53bd
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 19, 2025
0e3cf3b
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 23, 2025
2ca696d
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 25, 2025
67ead43
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 27, 2025
a6496a7
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Aug 28, 2025
b1bd6ec
Merge branch 'denoland:main' into rename-FreshContext-req-to-request
timreichen Aug 30, 2025
0f6b979
Merge branch 'main' into rename-FreshContext-req-to-request
timreichen Sep 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/canary/concepts/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ Contains the incoming

```ts
app.get("/", (ctx) => {
console.log("Request: ", ctx.req);
console.log("Request: ", ctx.request);

if (ctx.req.headers.has("X-Foo")) {
if (ctx.request.headers.has("X-Foo")) {
// do something
}

Expand Down
2 changes: 1 addition & 1 deletion docs/canary/examples/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ have a trailing slash at the end or that they will never have one.

Middleware, handler and route component signatures have been unified to all look
the same. Instead of receiving two arguments, they receive one. The `Request`
object is stored on the context object as `ctx.req`.
object is stored on the context object as `ctx.request`.

```diff middleware.ts
- const middleware = (req, ctx) => new Response("ok");
Expand Down
9 changes: 6 additions & 3 deletions packages/fresh/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class Context<State> {
* certain search parameters are set.
*/
readonly url: URL;
/** The original incoming {@linkcode Request} object. */
/** The original incoming `Request` object` */
readonly request: Request;
/** @deprecated This is an alias for internal use only. Use {@linkcode FreshContext[request]} instead. */
readonly req: Request;
/** The matched route pattern. */
readonly route: string | null;
Expand Down Expand Up @@ -126,7 +128,7 @@ export class Context<State> {
}

constructor(
req: Request,
request: Request,
url: URL,
info: Deno.ServeHandlerInfo,
route: string | null,
Expand All @@ -136,7 +138,8 @@ export class Context<State> {
buildCache: BuildCache<State>,
) {
this.url = url;
this.req = req;
this.request = request;
this.req = request;
this.info = info;
this.params = params;
this.route = route;
Expand Down
2 changes: 1 addition & 1 deletion packages/fresh/src/dev/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class Builder<State = any> {
await this.#ready.promise;
return ctx.next();
})
.all("*", (ctx) => appHandler(ctx.req, ctx.info));
.all("*", (ctx) => appHandler(ctx.request, ctx.info));

devApp.config.root = this.config.root;
devApp.config.mode = "development";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function automaticWorkspaceFolders<T>(root: string): Middleware<T> {
content ??= JSON.stringify({ workspace: { root, uuid } }, undefined, 2);
etag ??= await eTag(content);

const noneMatchValue = ctx.req.headers.get("if-none-match");
const noneMatchValue = ctx.request.headers.get("if-none-match");
if (!ifNoneMatch(noneMatchValue, etag)) {
return new Response(undefined, { status: 304, headers: { etag } });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function devErrorOverlay<T>(): Middleware<T> {
try {
return await ctx.next();
} catch (err) {
if (ctx.req.headers.get("accept")?.includes("text/html")) {
if (ctx.request.headers.get("accept")?.includes("text/html")) {
let init: ResponseInit | undefined;
if (err instanceof HttpError) {
if (err.status < 500) throw err;
Expand Down
6 changes: 3 additions & 3 deletions packages/fresh/src/dev/middlewares/live_reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export function liveReload<T>(): Middleware<T> {
const revision = Date.now();

return (ctx) => {
const { config, req, url } = ctx;
const { config, request, url } = ctx;

const aliveUrl = config.basePath + ALIVE_URL;

if (url.pathname === aliveUrl) {
if (req.headers.get("upgrade") !== "websocket") {
if (request.headers.get("upgrade") !== "websocket") {
return new Response(null, { status: 501 });
}

Expand All @@ -20,7 +20,7 @@ export function liveReload<T>(): Middleware<T> {
// the client to know when the server is back up. Once we
// have HMR we'll actively start sending messages back
// and forth.
const { response, socket } = Deno.upgradeWebSocket(req);
const { response, socket } = Deno.upgradeWebSocket(request);

socket.addEventListener("open", () => {
socket.send(
Expand Down
2 changes: 1 addition & 1 deletion packages/fresh/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function page<T>(data?: T, options?: {
*
* ```ts
* export const handlers = define.handlers((ctx) => {
* return new Response(`Hello from a ${ctx.req.method} request!`);
* return new Response(`Hello from a ${ctx.request.method} request!`);
* });
* ```
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/fresh/src/middlewares/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function cors<State>(options?: CORSOptions<State>): Middleware<State> {
const optsOrigin = opts.origin;

return async (ctx) => {
const requestOrigin = ctx.req.headers.get("origin") || "";
const requestOrigin = ctx.request.headers.get("origin") || "";

let allowOrigin: string | null = null;
if (typeof optsOrigin === "string") {
Expand All @@ -115,7 +115,7 @@ export function cors<State>(options?: CORSOptions<State>): Middleware<State> {
vary.add("Origin");
}

if (ctx.req.method === "OPTIONS") {
if (ctx.request.method === "OPTIONS") {
const headers = new Headers();

addHeaderProperties(
Expand All @@ -137,7 +137,7 @@ export function cors<State>(options?: CORSOptions<State>): Middleware<State> {

let allowHeaders = opts.allowHeaders;
if (!allowHeaders?.length) {
const reqHeaders = ctx.req.headers.get(
const reqHeaders = ctx.request.headers.get(
"Access-Control-Request-Headers",
);
if (reqHeaders) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fresh/src/middlewares/csrf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function csrf<State>(
};

return async (ctx) => {
const { method, headers } = ctx.req;
const { method, headers } = ctx.request;

// Safe methods
if (method === "GET" || method === "HEAD" || method === "OPTIONS") {
Expand Down
2 changes: 1 addition & 1 deletion packages/fresh/src/middlewares/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { recordSpanError, tracer } from "../otel.ts";
* // checking and code completion. It does not register the middleware with the
* // app.
* const loggerMiddleware = define.middleware((ctx) => {
* console.log(`${ctx.req.method} ${ctx.req.url}`);
* console.log(`${ctx.request.method} ${ctx.request.url}`);
* // Call the next middleware
* return ctx.next();
* });
Expand Down
8 changes: 4 additions & 4 deletions packages/fresh/src/middlewares/static_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getBuildCache } from "../context.ts";
*/
export function staticFiles<T>(): Middleware<T> {
return async function freshServeStaticFiles(ctx) {
const { req, url, config } = ctx;
const { request, url, config } = ctx;

const buildCache = getBuildCache(ctx);
if (buildCache === null) return await ctx.next();
Expand All @@ -36,7 +36,7 @@ export function staticFiles<T>(): Middleware<T> {
return await ctx.next();
}

if (req.method !== "GET" && req.method !== "HEAD") {
if (request.method !== "GET" && request.method !== "HEAD") {
file.close();
return new Response("Method Not Allowed", { status: 405 });
}
Expand Down Expand Up @@ -68,7 +68,7 @@ export function staticFiles<T>(): Middleware<T> {
vary: "If-None-Match",
});

const ifNoneMatch = req.headers.get("If-None-Match");
const ifNoneMatch = request.headers.get("If-None-Match");
if (
ifNoneMatch !== null &&
(ifNoneMatch === etag || ifNoneMatch === `W/"${etag}"`)
Expand Down Expand Up @@ -98,7 +98,7 @@ export function staticFiles<T>(): Middleware<T> {
}

headers.set("Content-Length", String(file.size));
if (req.method === "HEAD") {
if (request.method === "HEAD") {
file.close();
return new Response(null, { status: 200, headers });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/fresh/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function renderRouteComponent<State>(
info: ctx.info,
isPartial: ctx.isPartial,
params: ctx.params,
req: ctx.req,
req: ctx.request,
state: ctx.state,
url: ctx.url,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/fresh/src/segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function renderRoute<State>(
internals.layouts = [];
}

const method = ctx.req.method as Method;
const method = ctx.request.method as Method;

const handlers = route.handler;
if (handlers === undefined) {
Expand Down
10 changes: 5 additions & 5 deletions packages/fresh/tests/partials_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ Deno.test({
fn: async () => {
const app = testApp()
.post("/partial", async (ctx) => {
const data = await ctx.req.formData();
const data = await ctx.request.formData();
const name = data.get("name");
const submitter = data.get("submitter");
return ctx.render(
Expand Down Expand Up @@ -1875,7 +1875,7 @@ Deno.test({
);
})
.post("/partial", async (ctx) => {
const data = await ctx.req.formData();
const data = await ctx.request.formData();
const name = String(data.get("name"));

return new Response(null, {
Expand Down Expand Up @@ -1920,7 +1920,7 @@ Deno.test({
fn: async () => {
const app = testApp()
.post("/partial", async (ctx) => {
const data = await ctx.req.formData();
const data = await ctx.request.formData();
const name = data.get("name");
const submitter = data.get("submitter");
return ctx.render(
Expand Down Expand Up @@ -1979,7 +1979,7 @@ Deno.test({
fn: async () => {
const app = testApp()
.post("/partial", async (ctx) => {
const data = await ctx.req.formData();
const data = await ctx.request.formData();
const name = data.get("name");
const submitter = data.get("submitter");
return ctx.render(
Expand Down Expand Up @@ -2040,7 +2040,7 @@ Deno.test({
fn: async () => {
const app = testApp()
.post("/partial", async (ctx) => {
const data = await ctx.req.formData();
const data = await ctx.request.formData();
const name = data.get("name");
const submitter = data.get("submitter");
return ctx.render(
Expand Down
2 changes: 1 addition & 1 deletion packages/init/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ app.get("/api2/:name", (ctx) => {

// this can also be defined via a file. feel free to delete this!
const exampleLoggerMiddleware = define.middleware((ctx) => {
console.log(\`\${ctx.req.method} \${ctx.req.url}\`);
console.log(\`\${ctx.request.method} \${ctx.request.url}\`);
return ctx.next();
});
app.use(exampleLoggerMiddleware);
Expand Down
2 changes: 1 addition & 1 deletion packages/update/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function maybePrependReqVar(
declarationKind: tsmorph.VariableDeclarationKind.Const,
declarations: [{
name: paramName,
initializer: "ctx.req",
initializer: "ctx.request",
}],
});
}
Expand Down
Loading
Loading