Skip to content

Cache-Control Header keeps showing "public, max-age=0" #508

@akama-aka

Description

@akama-aka

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.2.1

Plugin version

8.1.0

Node.js version

20.18.2

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

rolling

Description

Hello,

as already described on the Discord server of Fastify, the documentation regarding the setHeader is extremely poor, at least I can't find any way to include the Cache-Control header functionally without getting back Cache-Control: public, max-age=0. Unfortunately there are also no tests or templates that rely on the setHeaders function despite the fact that Fastify, in my opinion, places an extremely high value on tests.

Anyway, back to the problem. I have already tried the following versions:

...
.register(require('@fastify/static'), {         // For all Static files like Styling, JavaScript Cde
        prefix: `/${process.env.PATH_IDENTIFIER}/assets/`,
        setHeaders: (res) => {
            res.setHeader('Cache-Control', 'public, immutable, max-age=2592000');
        },
        root: join(__dirname + '/public/assets/')
    })
...
...
.register(require('@fastify/static'), {         // For all Static files like Styling, JavaScript Cde
        prefix: `/${process.env.PATH_IDENTIFIER}/assets/`,
        setHeaders: (res) => {
            cacheControl: true,
            maxAge: 2592000
        },
        root: join(__dirname + '/public/assets/')
    })
...
...
.register(require('@fastify/static'), {         // For all Static files like Styling, JavaScript Cde
        prefix: `/${process.env.PATH_IDENTIFIER}/assets/`,
        setHeaders: (res) => {
            res.setHeaders({'Cache-Control': 'public, immutable, max-age=2592000'});
        },
        root: join(__dirname + '/public/assets/')
    })
....

and more.

I've seen some similar issues but they all use a Third Party Package which I don't want for something like that, that HAS TO BE easy to understand and implement

Link to code that reproduces the bug

https://github.com/akama-aka/cdn-cgi/pull/36

Expected Behavior

No response

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