1. The problem I’m having:
I am trying to serve multiple single-page applications with clientside routing. I have following folder structure:
> toplevel
- Caddyfile
> STATIC
> spa1
- index.html
> spa2
- index.html
> spa3
- index.html
...
Let’s say I get request for file /spa1/a
. How can I return for it file /spa1/index.html
? Hopefully without hand-coding configuration for each SPA.
3. Caddy version:
Caddy v2.6.3.
4. How I installed and ran Caddy:
Static binary for windows.
a. System environment:
Windows 10, no docker.
b. Command:
caddy run
d. My complete Caddy config:
:5400 {
root * ./STATIC
try_files {path} {path}.html {path}/ {path}/index.html
encode zstd gzip
file_server
}
I think I managed to solve my issue using:
:5400 {
@spa path_regexp spa ^(.*[\\\/])
handle @spa {
root * ./STATIC
try_files {path} {path}.html {path}/ {path}/index.html {re.spa.1}/index.html
encode zstd gzip
file_server
}
}
Can this approach pose any problems in future?
You’d be better off using a subdomain for each app.
app1.example.com {
root * /path/to/app1
encode gzip
try_files {path} {path}.html {path}/ /index.html
file_server
}
app2.example.com {
root * /path/to/app1
encode gzip
try_files {path} {path}.html {path}/ /index.html
file_server
}
Sadly I have to keep same urls as we currently have in apache.
system
(system)
Closed
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.