I’m have webpack-dev-server setup with Caddy but the config is ugly since I need to repeat each path to passthrough transparent proxy. It seems that regex isn’t supported. Is there any way to combine these together without putting them all into their own directory prefix?
Hi @dschissler, I’ve edited your post to add code blocks for readability.
You could try something like this:
rewrite {
if {path} match ^/(assets/|css/|js/|fonts/|webpack-dev-server|webpack-dev-server.js)
to /proxy{uri}
}
proxy /proxy localhost:8081 {
transparent
without /proxy
}
It’d probably be a fair bit faster, computationally speaking, to use multiple substring checks - and easier to read or modify, too:
rewrite {
if_op or # rewrite should execute if ANY check is true
if {path} starts_with /js/
if {path} starts_with /css/
if {path} starts_with /fonts/
if {path} starts_with /assets/
if {path} starts_with /webpack-dev-server
to /proxy{uri}
}
proxy /proxy localhost:8081 {
transparent
without /proxy
}
The other rewrite would probably also benefit from substring checks instead - no need to use a regex capture group, since we can simply use the {path} placeholder:
rewrite {
if_op and # rewrite shoule execute if ALL checks are true
if {path} not_starts_with /js/
if {path} not_starts_with /css/
if {path} not_starts_with /fonts/
if {path} not_starts_with /assets/
if {path} not_starts_with /webpack-dev-server
to /index.php?_url={path}
}