lume icon indicating copy to clipboard operation
lume copied to clipboard

New middleware for headers

Open oscarotero opened this issue 3 years ago • 6 comments

To add custom headers to some urls. So it could support something like this: https://docs.netlify.com/routing/headers/

oscarotero avatar Apr 15 '22 09:04 oscarotero

Did you already start creating the middleware? I started with the TS interfaces. If you have any code I can test with let me know.

jrson83 avatar Sep 08 '22 23:09 jrson83

No, I didn't start. If you want to give a try, I'll appreciate it :)

oscarotero avatar Sep 08 '22 23:09 oscarotero

I'm guessing this is related, but it would be nice if we could cache HTTP requests. It seems there is middleware for 'no-cache' but when I push a copy of (https://github.com/lumeland/base-blog/)[https://github.com/lumeland/base-blog/] to Vercel it does not cache any HTTP requests. I'm guessing the example at (https://lumeland.github.io/base-blog/)[https://lumeland.github.io/base-blog/] has HTTP headers automatically set within the GitHub service since there does not appear to be anything in the code setting the caching header.

(I just began playing with Lume today. I love it.)

kuhlaid avatar Oct 04 '22 19:10 kuhlaid

@kuhlaid These middlewares are used only for Deno runtime environment. Vercel doesn't run Deno (just serve statically the pages build by Lume). For cache, Lume has the expires middleware, that set the Expires header to the http responses. I think you can achieve something similar in Vercel by configuring your headers (more info: https://vercel.com/docs/project-configuration#project-configuration/headers)

oscarotero avatar Oct 04 '22 21:10 oscarotero

Thank you @oscarotero. I had tried setting the caching options in a vercel.json configuration but was not able to find a combo of header properties to get caching to fully work. I looked at https://lume-blog.vercel.app/ but it does not use caching. My use-case is at https://schm-website-ymxq58e94-kuhlaid.vercel.app/posts/secondpost/ and the pagefind-ui.js caches but not the /posts/secondpost/. This is with a vercel.json that looks like:

{
    "headers": [
        {
            "source": "/(.*)",
            "headers": [
                {
                    "key": "Cache-Control",
                    "value": "max-age=3600"
                }
            ]
        }
    ]
}

kuhlaid avatar Oct 05 '22 14:10 kuhlaid

@kuhlaid To me, your configuration works fine. The content is cached the first time and then it uses the cached version: image

PD: thanks for your post about Lume :)

oscarotero avatar Oct 05 '22 21:10 oscarotero