]> git.maquefel.me Git - brevno-suite/hugo/commit
Add some more server options/improvements
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 4 Feb 2025 17:21:24 +0000 (18:21 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 5 Feb 2025 17:14:15 +0000 (18:14 +0100)
commit029d1e0ced541450fe7f056eaa438a1f6ac28685
tree84eac5006183118585986739b4aa58ec9dcf2048
parente865d59844744e1446ebcfccdadebac6802aa34f
Add some more server options/improvements

New options:

* `FromHeaders`: Server header matching for redirects
* `FromRe`: Regexp with group support, i.e. it replaces $1, $2 in To with the group matches.

Note that if both `From` and `FromRe` is set, both must match.

Also

* Allow redirects to non HTML URLs as long as the Sec-Fetch-Mode is set to navigate on the request.
* Detect and stop redirect loops.

This was all done while testing out InertiaJS with Hugo. So, after this commit, this setup will support the main parts of the protocol that Inertia uses:

```toml
[server]
    [[server.headers]]
        for = '/**/inertia.json'
        [server.headers.values]
            Content-Type = 'text/html'
            X-Inertia    = 'true'
            Vary         = 'Accept'

    [[server.redirects]]
        force       = true
        from        = '/**/'
        fromRe      = "^/(.*)/$"
        fromHeaders = { "X-Inertia" = "true" }
        status      = 301
        to          = '/$1/inertia.json'
```

Unfortunately, a provider like Netlify does not support redirects matching by request headers. It should be possible with some edge function, but then again, I'm not sure that InertiaJS is a very good fit with the common Hugo use cases.

But this commit should be generally useful.
commands/server.go
config/commonConfig.go
config/commonConfig_test.go