Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected api endpoint availability #585

Open
teodorescuserban opened this issue Dec 11, 2024 · 5 comments · May be fixed by #589
Open

unexpected api endpoint availability #585

teodorescuserban opened this issue Dec 11, 2024 · 5 comments · May be fixed by #589

Comments

@teodorescuserban
Copy link

I am using souin as caddy module.

I only cache some of the requests. I was very surprised to notice (after a couple of hours of unsuccessful tries) that in certain configurations the souin api endpoint is not available. More precise, if a request to /souin-api/souin is not configured to be cached, the api won't respond.

Like in this Caddyfile example:

{
    cache
}

:80 {

    @somecache path /i-cache-this
    @nocache not path /i-cache-this

    route @somecache {
        cache
        respond "caching."
    }

    route @nocache {
        respond "not caching. and no souin api."    
    }
}

Now, I don't have a sane suggestion. My first instinct would tell me that it would be nice to have the souin-api endpoint liked to the caddy admin port instead. But there are a number of problems with that.

Perhaps the best solution would br to just document that (with a nice example of how to also secure the souin api endpoint from external).

Keep up the good work, @darkweak !

@darkweak
Copy link
Owner

Hey @teodorescuserban I plan to bring this feature in the PR #589.

@darkweak
Copy link
Owner

@teodorescuserban you can already try it using:

xcaddy build --with github.com/darkweak/souin@e5c1440eb3a0c1c6832488a6605e842c09ecc04a --with github.com/darkweak/souin/plugins/caddy@e5c1440eb3a0c1c6832488a6605e842c09ecc04a

and send the following request (assuming you're running it on localhost and enabled souin api in the config):

curl http://localhost:2019/souin-api/souin

@teodorescuserban
Copy link
Author

@darkweak maybe wrong sha?

65.45 go: upgraded google.golang.org/protobuf v1.34.1 => v1.34.2
65.45 2025/01/22 14:34:36 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -v github.com/darkweak/souin@e5c1440eb3a0c1c6832488a6605e842c09ecc04a github.com/caddyserver/caddy/[email protected]
79.74 go: github.com/darkweak/souin@e5c1440eb3a0c1c6832488a6605e842c09ecc04a: invalid version: unknown revision e5c1440eb3a0c1c6832488a6605e842c09ecc04a
79.74 2025/01/22 14:34:51 [FATAL] exit status 1
------
Dockerfile:13
--------------------
  12 |
  13 | >>> RUN CGO_ENABLED=0 GOARCH=${TARGETARCH} GOOS=${TARGETOS} \
  14 | >>>     xcaddy build \
...
  21 | >>>     --with github.com/darkweak/storages/go-redis/caddy \
  22 | >>>     --with github.com/darkweak/souin@e5c1440eb3a0c1c6832488a6605e842c09ecc04a \
  23 | >>>     --with github.com/darkweak/souin/plugins/caddy@e5c1440eb3a0c1c6832488a6605e842c09ecc04a
  24 |

@darkweak
Copy link
Owner

@teodorescuserban this one fad3f2f3162e1f9f588fa7a4bb70cdaa41403374 should work. The previous one had a panic error.

@teodorescuserban
Copy link
Author

teodorescuserban commented Jan 22, 2025

I tested it and it works! However, setting basepath or souin basepath seems to break it; I mean it doesn't work with the baseline settings or any permutation (/souin-api/souin, /souin-api/keys,/cache/souin,/cache/keys)

My cache config looks like this:

cache {
        ...
        api {
                basepath /cache
                debug
                prometheus
                souin {
                       basepath /keys
                }
        }
}

It will only work with this config:

cache {
        ...
        api {
                # basepath /cache
                debug
                prometheus
                souin # {
                #       basepath /keys
                # }
        }
}

It does look promising though, @darkweak !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants