Skip to content

Unable to set Custom Response header via edge function #34

Open
@kriordan37

Description

@kriordan37

Following the documentation I was able get the hello world edge function running and to verify it via the netlify cli. However when I switch out the body of the test.ts file with response edge function to:

import type { Context } from "https://edge.netlify.com";

export default async (request: Request, context: Context) => {
  const url = new URL(request.url);

  if (url.searchParams.get("method") !== "set-response-header") {
    return context.next();
  }

  context.log(`Adding a custom header to the response for ${url}`);

  const response = await context.next();
  response.headers.set("X-Your-Custom-Header", "Your custom header value");
  return response;
};

and update the netlify.tomi to

[[edge_functions]] 
path = "/*"
function = "hello"

I can see that the edge function is◈ Loaded edge function hello up via the --edgeInspect flag, but when inspected the page I do not see the reponse header. Connecting the debugger doesn't lead to much helpful information that I can see.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions