Skip to content

Response Headers for Expiration, Age #1586

Answered by RobinTail
lpw asked this question in Q&A
Discussion options

You must be logged in to vote

I presume you're talking about this header:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age

You can set headers either from a Middleware or from ResultHandler, @lpw

The handlers of those entities have response argument, so you can do response.set():
https://expressjs.com/en/api.html#res.set

const shortTermFactory = defaultEndpointsFactory
  .addMiddleware(
    createMiddleware({
      input: z.object({}),
      middleware: async ({ response }) => {
        response.set("age", 30);
        return {};
      }
    })
  );

The endpoints produced on shortTermFactory are going to have the header set.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by RobinTail
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants