Caddy: Client-side reload not working with 0.10.4 version

Created on 3 Jul 2017  路  7Comments  路  Source: caddyserver/caddy

1. What version of Caddy are you using (caddy -version)?

0.10.4

2. What are you trying to do?

We just got updated from 0.10.3 to 0.10.4.
We have a Single Page App using ember so I just created an example app in order to reproduce the problem.
With version 0.10.4 when I forced a reload on the browser I was redirected to / and with version 0.10.3 it worked.

3. What is your entire Caddyfile?

0.0.0.0:4200 {

    # Logging & error to stdout so docker can grabit
    log stdout
    errors stdout

    # Enable gzip compression
    gzip

    # Serve ember statics.
    root   /code/super-rentals/dist

    # Healthcheck (file created on image build).
    rewrite /check {
        to /check.txt
    }

    # Redirect all HTTP to HTTPS requests coming from the ELB (the one that sets X-Forwarded-Proto header).
    redir 301 {
        if {>X-Forwarded-Proto} is http
        /  https://{host}{uri}
    }

    # If not API call then redirect to slashed URL and serve index.html (Ember routing).
    rewrite {
        if {path} not_has /api
        to {path} {path}/ /index.html
    }

    # Transparent proxy (Proxypass) API calls to the backend.
    proxy /api {$BACKEND_BASE_URL} {
        transparent
    }
}

Ref: https://github.com/themotion/caddy-bug/blob/master/environment/prod/Caddyfile

4. How did you run Caddy (give the full command and describe the execution environment)?

exec /usr/local/bin/caddy --conf /etc/Caddyfile --log stdout
Ref: https://github.com/themotion/caddy-bug/blob/master/environment/prod/run.sh

5. Please paste any relevant HTTP request(s) here.

LOAD http://localhost:4200/rentals
CLICK http://localhost:4200/rentals/grand-old-mansion
RELOAD ON BROWSER

6. What did you expect to see?

172.17.0.1 - - [03/Jul/2017:14:21:39 +0000] "GET / HTTP/1.1" 200 1164
172.17.0.1 - - [03/Jul/2017:14:21:39 +0000] "GET /assets/super-rentals-d41d8cd98f00b204e9800998ecf8427e.css HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:21:39 +0000] "GET /assets/vendor-d2ee028656a71a6e38f2c3c3604255d3.css HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:21:39 +0000] "GET /assets/vendor-62cc3d841685c12e3ba46965b23fa331.js HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:21:39 +0000] "GET /assets/super-rentals-4738967b3949fb79e7b027f4be05d6e2.js HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:21:40 +0000] "GET /assets/images/teaching-756a14cc8225582bf530b5d0c624db4d.png HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:22:15 +0000] "GET /rentals/grand-old-mansion HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:22:15 +0000] "GET /assets/vendor-d2ee028656a71a6e38f2c3c3604255d3.css HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:22:15 +0000] "GET /assets/super-rentals-d41d8cd98f00b204e9800998ecf8427e.css HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:22:15 +0000] "GET /assets/vendor-62cc3d841685c12e3ba46965b23fa331.js HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:22:15 +0000] "GET /assets/super-rentals-4738967b3949fb79e7b027f4be05d6e2.js HTTP/1.1" 304 0
172.17.0.1 - - [03/Jul/2017:14:22:17 +0000] "GET /assets/images/teaching-756a14cc8225582bf530b5d0c624db4d.png HTTP/1.1" 304 0

7. What did you see instead (give full error messages and/or log)?

172.17.0.1 - - [03/Jul/2017:14:23:33 +0000] "GET / HTTP/1.1" 200 1164
172.17.0.1 - - [03/Jul/2017:14:23:33 +0000] "GET /assets/super-rentals-d41d8cd98f00b204e9800998ecf8427e.css HTTP/1.1" 200 23
172.17.0.1 - - [03/Jul/2017:14:23:33 +0000] "GET /assets/vendor-d2ee028656a71a6e38f2c3c3604255d3.css HTTP/1.1" 200 1244
172.17.0.1 - - [03/Jul/2017:14:23:33 +0000] "GET /assets/super-rentals-4738967b3949fb79e7b027f4be05d6e2.js HTTP/1.1" 200 4736
172.17.0.1 - - [03/Jul/2017:14:23:33 +0000] "GET /assets/vendor-62cc3d841685c12e3ba46965b23fa331.js HTTP/1.1" 200 490619
172.17.0.1 - - [03/Jul/2017:14:23:34 +0000] "GET /assets/images/teaching-756a14cc8225582bf530b5d0c624db4d.png HTTP/1.1" 200 91673
172.17.0.1 - - [03/Jul/2017:14:23:42 +0000] "GET /rentals/grand-old-mansion HTTP/1.1" 301 60
172.17.0.1 - - [03/Jul/2017:14:23:42 +0000] "GET / HTTP/1.1" 304 0

8. How can someone who is starting from scratch reproduce the bug as minimally as possible?

I have created a repo with a container where you can reproduce it.
In the readme is explained how to run it.
You can change caddy version in this file: https://github.com/themotion/caddy-bug/blob/master/environment/prod/Dockerfile

duplicate

Most helpful comment

I should have read the closed issues. https://github.com/mholt/caddy/issues/1737#issuecomment-312294705 solved my issue.

Might also solve @cesarob issue by changing

````

If not API call then redirect to slashed URL and serve index.html (Ember routing).

rewrite {
if {path} not_has /api
to {path} {path}/ /index.html
}
to

If not API call then redirect to slashed URL and serve index.html (Ember routing).

rewrite {
if {path} not_has /api
to {path} {path}/ /
}
````

All 7 comments

After isolating the issue with ember I just did a very dump example with a couple of html files (and index and a second one) and it worked properly.

172.17.0.1 - - [03/Jul/2017:15:40:57 +0000] "GET / HTTP/1.1" 200 81
172.17.0.1 - - [03/Jul/2017:15:41:00 +0000] "GET /foo.html HTTP/1.1" 200 69
172.17.0.1 - - [03/Jul/2017:15:41:03 +0000] "GET /foo.html HTTP/1.1" 304 0

It looks ember has something to do in this game...

The wrong request as curl

$ curl -v 'http://localhost:4200/rentals/grand-old-mansion' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: es-ES,es;q=0.8,en;q=0.6' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Cache-Control: max-age=0' -H 'Cookie: gsScrollPos=; host=.butterfly; io=U3BIOedZcFeMiY7SAAAC; session=.eJwNyjEOwjAMBdC7eO5g0sR2e5ko8XdEVQRSw4a4O7z5faiOK-ad9tEeMxaqB2gn4wyYIklXGFtGN01ROLirMWghn9eo79cZz__PsqUuXLYUN2HIKt5UObGoywp4dvMWhb4_YfUgWw.DBAo0A.P8142jHlxBxNPCvwtritlyDi9Tw; gsScrollPos-640=0; gsScrollPos-118=0; gsScrollPos-135=0; wiggumio_jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE0OTg0OTcyNDIsInVzZXIiOnsiZmlyc3RfbmFtZSI6IlRlYW0tMCIsInVzZXJuYW1lIjoidGVhbS0wIiwiaWQiOjE1LCJlbWFpbCI6InRlY2grdGVhbTBAdGhlbW90aW9uLmNvbSIsImxhc3RfbmFtZSI6IiJ9LCJpc3MiOiJ3aWdndW1pb19kZXYiLCJ2ZXJzaW9uIjoxLjEsImV4cCI6MTQ5OTc5MzI1NywiaWF0IjoxNDk4NDk3MjU3fQ.GQ0jubudo6eY3d38FYVrOegQeCjyanTVp44AiopiR6Y; sessionid=z5ynglhqse0kgqu86uhpmjn5q9239dhm; csrftoken=SgFGzKz4rLrRzhwEB50feZqihbCSlGSp; djdt=show; gsScrollPos-63=0; gsScrollPos-33=0; _okdetect=%7B%22token%22%3A%2214985791472950%22%2C%22proto%22%3A%22http%3A%22%2C%22host%22%3A%22localhost%3A4040%22%7D; olfsk=olfsk4997053693318403; _okbk=cd4%3Dtrue%2Cvi5%3D0%2Cvi4%3D1498579147793%2Cvi3%3Dactive%2Cvi2%3Dfalse%2Cvi1%3Dfalse%2Ccd8%3Dchat%2Ccd6%3D0%2Ccd5%3Daway%2Ccd3%3Dfalse%2Ccd2%3D0%2Ccd1%3D0%2C; _ok=1700-237-10-3483; wcsid=vSqIO6N0FBdi0TvN3m39N0NFREoOrB6r; hblid=siaOq2skAg0QXkTM3m39N0NFREB6BrS9; themotion_id=gAAAAABZUoDb9uZDjYPX-l4NHtnf1SyKunPFyNT9AWJOiZSr0gR0NdGoKYQ75JTpPeZJyUPr3H4QU6kvgnfMwAZMJuUVv2x7aL0CqpSzLfnrcxKLSlpR-45RIsl7siWYwsV0zHHgCECR0mvOkjTD-K4XkRmTZp3UKCTb9ypj1ne-ncJIAgASU-JoFCz4EA1Liz11W1_Z09U-j8F2miTVVwo3dLjswmmudxWzRLhjHs0WG6LvvkH_FnleqqKfKROQS8j2LcnT2VHpIn6lY2w8YTxfWqaTNOrUF-yQzV_FgHbuLFWxIszGe_LJITkKqgbuJfYl3Lw2fydD16oXyVwuVCRGJkbawR1CUItd3Jdcr15Anw3hH64PLviznyLbwtlEBQ8CT1z3WPOcQOqybKAzyTLBs2Q0RMiKKe8HH-rOz3PkWYMTbTU7FjWtyx1FKNvKKHB6TkwQ0chunIutYgCqJBGQsbAtXZnYH0kdOkGMDxmTAcqxD09cJUHT_5-Fz0GbuXTg7A4Xxeaqowz_Ss7bNcQsMTPH85STuaVX-8WC0j3IIn6uMoOM3QRk3KcpMDkNSc4gZEt7fpYEACu6Nt38q_VpYzzUncWbEH9xchwwq7rW8ndzUQgSCRkV1xXYzw9FvJXxBaC1FMXi; mp_4e60f15935602f876bb9ea2e8ac320ce_mixpanel=%7B%22distinct_id%22%3A%20%2215ccb581a08118-05fd7fd06fb12a-1c2f1702-1fa400-15ccb581a095b%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%7D; _oklv=1498583050099%2CvSqIO6N0FBdi0TvN3m39N0NFREoOrB6r' -H 'Connection: keep-alive' --compressed
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4200 (#0)
> GET /rentals/grand-old-mansion HTTP/1.1
> Host: localhost:4200
> Accept-Encoding: gzip, deflate, br
> Accept-Language: es-ES,es;q=0.8,en;q=0.6
> Upgrade-Insecure-Requests: 1
> User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
> Cache-Control: max-age=0
> Cookie: gsScrollPos=; host=.butterfly; io=U3BIOedZcFeMiY7SAAAC; session=.eJwNyjEOwjAMBdC7eO5g0sR2e5ko8XdEVQRSw4a4O7z5faiOK-ad9tEeMxaqB2gn4wyYIklXGFtGN01ROLirMWghn9eo79cZz__PsqUuXLYUN2HIKt5UObGoywp4dvMWhb4_YfUgWw.DBAo0A.P8142jHlxBxNPCvwtritlyDi9Tw; gsScrollPos-640=0; gsScrollPos-118=0; gsScrollPos-135=0; wiggumio_jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE0OTg0OTcyNDIsInVzZXIiOnsiZmlyc3RfbmFtZSI6IlRlYW0tMCIsInVzZXJuYW1lIjoidGVhbS0wIiwiaWQiOjE1LCJlbWFpbCI6InRlY2grdGVhbTBAdGhlbW90aW9uLmNvbSIsImxhc3RfbmFtZSI6IiJ9LCJpc3MiOiJ3aWdndW1pb19kZXYiLCJ2ZXJzaW9uIjoxLjEsImV4cCI6MTQ5OTc5MzI1NywiaWF0IjoxNDk4NDk3MjU3fQ.GQ0jubudo6eY3d38FYVrOegQeCjyanTVp44AiopiR6Y; sessionid=z5ynglhqse0kgqu86uhpmjn5q9239dhm; csrftoken=SgFGzKz4rLrRzhwEB50feZqihbCSlGSp; djdt=show; gsScrollPos-63=0; gsScrollPos-33=0; _okdetect=%7B%22token%22%3A%2214985791472950%22%2C%22proto%22%3A%22http%3A%22%2C%22host%22%3A%22localhost%3A4040%22%7D; olfsk=olfsk4997053693318403; _okbk=cd4%3Dtrue%2Cvi5%3D0%2Cvi4%3D1498579147793%2Cvi3%3Dactive%2Cvi2%3Dfalse%2Cvi1%3Dfalse%2Ccd8%3Dchat%2Ccd6%3D0%2Ccd5%3Daway%2Ccd3%3Dfalse%2Ccd2%3D0%2Ccd1%3D0%2C; _ok=1700-237-10-3483; wcsid=vSqIO6N0FBdi0TvN3m39N0NFREoOrB6r; hblid=siaOq2skAg0QXkTM3m39N0NFREB6BrS9; themotion_id=gAAAAABZUoDb9uZDjYPX-l4NHtnf1SyKunPFyNT9AWJOiZSr0gR0NdGoKYQ75JTpPeZJyUPr3H4QU6kvgnfMwAZMJuUVv2x7aL0CqpSzLfnrcxKLSlpR-45RIsl7siWYwsV0zHHgCECR0mvOkjTD-K4XkRmTZp3UKCTb9ypj1ne-ncJIAgASU-JoFCz4EA1Liz11W1_Z09U-j8F2miTVVwo3dLjswmmudxWzRLhjHs0WG6LvvkH_FnleqqKfKROQS8j2LcnT2VHpIn6lY2w8YTxfWqaTNOrUF-yQzV_FgHbuLFWxIszGe_LJITkKqgbuJfYl3Lw2fydD16oXyVwuVCRGJkbawR1CUItd3Jdcr15Anw3hH64PLviznyLbwtlEBQ8CT1z3WPOcQOqybKAzyTLBs2Q0RMiKKe8HH-rOz3PkWYMTbTU7FjWtyx1FKNvKKHB6TkwQ0chunIutYgCqJBGQsbAtXZnYH0kdOkGMDxmTAcqxD09cJUHT_5-Fz0GbuXTg7A4Xxeaqowz_Ss7bNcQsMTPH85STuaVX-8WC0j3IIn6uMoOM3QRk3KcpMDkNSc4gZEt7fpYEACu6Nt38q_VpYzzUncWbEH9xchwwq7rW8ndzUQgSCRkV1xXYzw9FvJXxBaC1FMXi; mp_4e60f15935602f876bb9ea2e8ac320ce_mixpanel=%7B%22distinct_id%22%3A%20%2215ccb581a08118-05fd7fd06fb12a-1c2f1702-1fa400-15ccb581a095b%22%2C%22%24initial_referrer%22%3A%20%22%24direct%22%2C%22%24initial_referring_domain%22%3A%20%22%24direct%22%7D; _oklv=1498583050099%2CvSqIO6N0FBdi0TvN3m39N0NFREoOrB6r
> Connection: keep-alive
> 
< HTTP/1.1 301 Moved Permanently
< Content-Encoding: gzip
< Location: /
< Server: Caddy
< Vary: Accept-Encoding
< Date: Mon, 03 Jul 2017 16:05:56 GMT
< Content-Length: 60
< Content-Type: application/x-gzip
< 
<a href="/">Moved Permanently</a>.

* Connection #0 to host localhost left intact

Hey, thanks for the detailed report and replication instructions!

It's a big holiday in the US tomorrow so I'm offline for a bit. But quick question, is /rentals/grand-old-mansion a directory or a file on disk?

It is not. There is just one .html the index.html.

I just upgraded to 0.10.4 from 0.9.5) and I've got a similar issue with a single page Angular application.

With this config
rewrite / { if {>Upgrade} not websocket if {file} not_has . to /index.html }
I get 301 for every path and for index.html. Accessing other files (containing .) still works. The result is that my site is no longer working because of too many redirect errors in the browsers. Commenting out that code and my site works again (except for the wanted redirects, obviously).

I should have read the closed issues. https://github.com/mholt/caddy/issues/1737#issuecomment-312294705 solved my issue.

Might also solve @cesarob issue by changing

````

If not API call then redirect to slashed URL and serve index.html (Ember routing).

rewrite {
if {path} not_has /api
to {path} {path}/ /index.html
}
to

If not API call then redirect to slashed URL and serve index.html (Ember routing).

rewrite {
if {path} not_has /api
to {path} {path}/ /
}
````

^ I was wondering that. Thanks for clarifying, Dennis. Will close now, assuming that to be the same problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kilpatty picture kilpatty  路  3Comments

aeroxy picture aeroxy  路  3Comments

PhilmacFLy picture PhilmacFLy  路  3Comments

ericmdantas picture ericmdantas  路  3Comments

billop picture billop  路  3Comments