Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Rename _req used to req #2349

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions docs/latest/examples/dealing-with-cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ deal with "preflight requests". Let's imagine you're trying to support a
```ts routes/_middleware.ts
import { FreshContext } from "$fresh/server.ts";

export async function handler(_req: Request, ctx: FreshContext) {
if (_req.method == "OPTIONS") {
export async function handler(req: Request, ctx: FreshContext) {
if (req.method == "OPTIONS") {
const resp = new Response(null, {
status: 204,
});
const origin = _req.headers.get("Origin") || "*";
const origin = req.headers.get("Origin") || "*";
const headers = resp.headers;
headers.set("Access-Control-Allow-Origin", origin);
headers.set("Access-Control-Allow-Methods", "DELETE");
return resp;
}
const origin = _req.headers.get("Origin") || "*";
const origin = req.headers.get("Origin") || "*";
const resp = await ctx.next();
const headers = resp.headers;

Expand Down
6 changes: 3 additions & 3 deletions tests/fixture/routes/_middleware.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { FreshContext, MiddlewareHandler } from "$fresh/server.ts";

// cors middleware
async function corsHandler(_req: Request, ctx: FreshContext) {
if (_req.method == "OPTIONS") {
async function corsHandler(req: Request, ctx: FreshContext) {
if (req.method == "OPTIONS") {
return new Response(null, {
status: 204,
});
}
const origin = _req.headers.get("Origin") || "*";
const origin = req.headers.get("Origin") || "*";
const resp = await ctx.next();
const headers = resp.headers;

Expand Down
Loading