React site is blank when uploaded to server

1. Caddy version (caddy version):

v2.4.5 h1:P1mRs6V2cMcagSPn+NWpD+OEYUYLIf6ecOa48cFGeUg=

2. How I run Caddy:

Using systemctl / systemd; “sudo systemctl daemon-reload”

a. System environment:

Ubuntu 18.04 (LTS) x64

b. Command:

reload the service ->
sudo systemctl daemon-reload

install the service ->
sudo sh -c 'curl https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service > /etc/systemd/system/caddy.service'

c. Service/unit/compose file:

N/A
Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddyfile or JSON config:

testing-twp.haula.net/ {

  log {
    level DEBUG
    output file /var/log/caddy/access.log {
      roll_size 10MiB
      roll_keep 10
      roll_keep_for 336h
    }
  }

  handle_path /api* {
    reverse_proxy localhost:3004
    #log {
    #   level DEBUG
    #   output file /caddy/access.log {
    #       roll_size 10MiB
    #       roll_keep 10
    #       roll_keep_for 336h
    #   }
    #}
#    log stdout
#    errors stdout
  }

  handle {
    root * /var/www/html/test
    encode gzip
    try_files {path} /index.html
    file_server
  }
}

3. The problem I’m having:

I am trying to load my React site on my Digital Ocean server and the site ends up being blank. It works fine on my PC, but when I upload it, it is just blank.

4. Error messages and/or full log output:

The only errors/warnings in the console are:
The script from “Together We Profit was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.
The script from “Together We Profit was loaded even though its MIME type (“”) is not a valid JavaScript MIME type.

5. What I already tried:

I created a basic “hello world” index file. And that loaded just fine. I created the basic React app with create-react-app and pushed that. That wouldn’t load either, just blank.

My site is: https://testing-twp.haula.net/

6. Links to relevant resources:

The problem is the / you have there.

When you put a /, Caddy sets up a path matcher for that site block. Since path matching is exact, this means it would only match requests to exactly / and nothing else.

So any other request will not match, and will fall through to Caddy’s default behaviour of an empty response (this is because “technically Caddy worked as configured”, but didn’t have anything else to do – no error, so you just get an empty response).

I removed that slash and unfortunately, it is still coming up as blank. I made sure to reload caddy with sudo systemctl daemon-reload after my changes too.

That doesn’t reload Caddy, that reloads the systemd config. Use sudo systemctl reload caddy.

Wow, that was it! Works perfect!! Thank you so much!

2 Likes

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