Can't get route work work

1. The problem I’m having:

I cannot get caddy to match this:

route /api/v1/uploadvideo/{project_name}/{user_name}

2. Error messages and/or full log output:

sudo /usr/bin/caddy run --config /etc/caddy/Caddyfile
2024/05/22 20:29:19.336	INFO	using provided configuration	{"config_file": "/etc/caddy/Caddyfile", "config_adapter": ""}
2024/05/22 20:29:19.338	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//127.0.0.1:2019", "//localhost:2019", "//[::1]:2019"]}
2024/05/22 20:29:19.338	WARN	http.auto_https	automatic HTTPS is completely disabled for server	{"server_name": "srv0"}
2024/05/22 20:29:19.338	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0xc00042dc80"}
2024/05/22 20:29:19.338	DEBUG	http.auto_https	adjusted config	{"tls": {"automation":{"policies":[{}]}}, "http": {"servers":{"srv0":{"listen":[":80"],"routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"subroute","routes":[{"handle":[{"body":"response 1","handler":"static_response","status_code":200}]}]}],"match":[{"path":["/api/v1/uploadvideo/{project_name}/{user_name}"]}]},{"handle":[{"handler":"subroute","routes":[{"handle":[{"body":"response 2","handler":"static_response","status_code":200}]}]}],"match":[{"path":["/api/v1/uploadvideo/*"]}]},{"handle":[{"handler":"subroute","routes":[{"handle":[{"body":"response 3","handler":"static_response","status_code":200}]}]}],"match":[{"path":["/api/*"]}]}]}],"terminal":true}],"automatic_https":{"disable":true}}}}}
2024/05/22 20:29:19.339	DEBUG	http	starting server loop	{"address": "[::]:80", "tls": false, "http3": false}
2024/05/22 20:29:19.339	INFO	http.log	server running	{"name": "srv0", "protocols": ["h1", "h2", "h3"]}
2024/05/22 20:29:19.339	INFO	autosaved config (load with --resume flag)	{"file": "/root/.config/caddy/autosave.json"}
2024/05/22 20:29:19.339	INFO	serving initial configuration
2024/05/22 20:29:19.450	WARN	tls	storage cleaning happened too recently; skipping for now	{"storage": "FileStorage:/root/.local/share/caddy", "instance": "b4e0cb70-e002-4d4c-997a-97846c91d775", "try_again": "2024/05/23 20:29:19.450", "try_again_in": 86399.999998802}
2024/05/22 20:29:19.450	INFO	tls	finished cleaning storage units
^C2024/05/22 20:32:18.978	INFO	shutting down	{"signal": "SIGINT"}
2024/05/22 20:32:18.978	WARN	exiting; byeee!! 👋	{"signal": "SIGINT"}
2024/05/22 20:32:18.979	INFO	http	servers shutting down with eternal grace period
2024/05/22 20:32:18.979	INFO	admin	stopped previous server	{"address": "localhost:2019"}
2024/05/22 20:32:18.979	INFO	shutdown complete	{"signal": "SIGINT", "exit_code": 0}

3. Caddy version:

caddy --version
v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

Sorry cannot recall.

a. System environment:

Ubuntu 22.04.4 LTS
Intel

b. Command:

sudo /usr/bin/caddy run --config /etc/caddy/Caddyfile

c. Service/unit/compose file:

d. My complete Caddy config:

{
	debug
	auto_https off
}

www.powergrabber.com:80 {
	route /api/v1/uploadvideo/{project_name}/{user_name} {
		respond "response 1" 200
	}

	route /api/v1/uploadvideo/* {
		respond "response 2" 200
	}

	route /api/* {
		respond "response 3" 200
	}
}

5. Links to relevant resources:

None of the curl commands I enter result in this route responding:

route /api/v1/uploadvideo/{project_name}/{user_name}


curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/uploadvideo
response 3%
curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/foo
response 3%
curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/uploadvideo/rabbits
response 2%
curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/uploadvideo/rabbits/dogs
response 2%
curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/uploadvideo/rabbits/dogs/
response 2%
curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/uploadvideo/
response 2%
curl -H "Host: www.powergrabber.com" http://192.168.0.130/api/v1/uploadvideo/rabbits/dogs/monkeys
response 2%

Hello @Duke_Dougal,

According to ICANN Lookup the Authoritative Nameservers are:

Yet none of them gives a response for powergrabber.com
or www.powergrabber.com

$ nslookup powergrabber.com NS-1500.AWSDNS-59.ORG.
Server:         NS-1500.AWSDNS-59.ORG.
Address:        205.251.197.220#53

** server can't find powergrabber.com: REFUSED
$ nslookup powergrabber.com NS-1859.AWSDNS-40.CO.UK.
Server:         NS-1859.AWSDNS-40.CO.UK.
Address:        205.251.199.67#53

** server can't find powergrabber.com: REFUSED
$ nslookup powergrabber.com NS-19.AWSDNS-02.COM.
Server:         NS-19.AWSDNS-02.COM.
Address:        205.251.192.19#53

** server can't find powergrabber.com: REFUSED
$ nslookup powergrabber.com NS-761.AWSDNS-31.NET.
Server:         NS-761.AWSDNS-31.NET.
Address:        205.251.194.249#53

** server can't find powergrabber.com: REFUSED
$ nslookup www.powergrabber.com NS-1500.AWSDNS-59.ORG.
Server:         NS-1500.AWSDNS-59.ORG.
Address:        205.251.197.220#53

** server can't find www.powergrabber.com: REFUSED
$ nslookup www.powergrabber.com NS-1859.AWSDNS-40.CO.UK.
Server:         NS-1859.AWSDNS-40.CO.UK.
Address:        205.251.199.67#53

** server can't find www.powergrabber.com: REFUSED
$ nslookup www.powergrabber.com NS-19.AWSDNS-02.COM.
Server:         NS-19.AWSDNS-02.COM.
Address:        205.251.192.19#53

** server can't find www.powergrabber.com: REFUSED
$ nslookup www.powergrabber.com NS-761.AWSDNS-31.NET.
Server:         NS-761.AWSDNS-31.NET.
Address:        205.251.194.249#53

** server can't find www.powergrabber.com: REFUSED
1 Like

The problem is you’re using {project_name} and {user_name} while making the request for

The matcher you’re using is literal, meaning it will literally look for {project_name} and {user_name} in the URL. Indeed, your request URL does not match those literal values, so it falls to the next matching one, which is /api/v1/uploadvideo/.

Try the path_regexp matcher

2 Likes

I recommend using handle instead of route to set up mutually exclusive routes.

http://www.powergrabber.com {
	@project path_regexp project ^/api/v1/uploadvideo/([^/]*)/([^/]*)
	handle @project {
		respond "Project: {re.project.1}, User: {re.project.2}"
	}

	handle /api/v1/uploadvideo/* {
		respond "uploadvideo"
	}

	handle /api/* {
		respond "api"
	}
}
1 Like

Hi Bruce,

The domain isn’t hooked up - I don’t think it should matter for the given example should it? Nothing should be touching the DNS in the test case I put together.

thanks

Thanks @francislavoie

Is the regex necessary in this case? Is that the only way to match that sort of path I have specified?

thanks

A path matcher with /api/v1/uploadvideo/*/* might work too, I think, but if you want to capture the project/username to use in some way in your config, then yeah the regexp is the way to go.

2 Likes

I will leave that to the more knowledgeable Caddy community volunteers. :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.