When use handle_path and file_server to deploy a react program , it doesn't work

1. The problem I’m having:

Use file_server with root path, it work well, but when i try to use handle_path, the react program not work.

2. Error messages and/or full log output:

Debug logs looks normal.

----root path
2023/07/01 17:56:44.160 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_ip": "10.1.0.6", "remote_port": "55036", "proto": "HTTP/1.1", "method": "GET", "host": "10.1.0.199", "uri": "/", "headers": {"Upgrade-Insecure-Requests": ["1"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"], "Accept-Encoding": ["gzip, deflate"], "Pragma": ["no-cache"], "Accept-Language": ["zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6"], "Cookie": [], "Connection": ["keep-alive"], "Cache-Control": ["no-cache"]}}, "method": "GET", "uri": "/index.html"}
2023/07/01 17:56:44.160 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/index.html", "result": "/home/wxy/www/sms-server/build/index.html"}
2023/07/01 17:56:44.160 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/index.html"}
2023/07/01 17:56:44.176 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/js/main.4586af2c.js", "result": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js"}
2023/07/01 17:56:44.176 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js"}
2023/07/01 17:56:44.177 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/css/main.e6c13ad2.css", "result": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css"}
2023/07/01 17:56:44.179 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css"}
2023/07/01 17:56:44.204 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/css/main.e6c13ad2.css.map", "result": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css.map"}
2023/07/01 17:56:44.205 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css.map"}
2023/07/01 17:56:44.273 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/js/main.4586af2c.js.map", "result": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js.map"}
2023/07/01 17:56:44.273 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js.map"}
2023/07/01 17:56:44.400 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/favicon.ico", "result": "/home/wxy/www/sms-server/build/favicon.ico"}
2023/07/01 17:56:44.400 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/favicon.ico"}


----handle_path
2023/07/01 17:57:15.265 DEBUG   http.handlers.rewrite   rewrote request {"request": {"remote_ip": "10.1.0.6", "remote_port": "55035", "proto": "HTTP/1.1", "method": "GET", "host": "10.1.0.199", "uri": "/sms-srv", "headers": {"Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Cache-Control": ["no-cache"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"], "Accept": ["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"], "Pragma": ["no-cache"], "Upgrade-Insecure-Requests": ["1"], "Accept-Language": ["zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6"], "Cookie": []}}, "method": "GET", "uri": "/index.html"}
2023/07/01 17:57:15.265 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/index.html", "result": "/home/wxy/www/sms-server/build/index.html"}
2023/07/01 17:57:15.265 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/index.html"}
2023/07/01 17:57:15.279 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/js/main.4586af2c.js", "result": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js"}
2023/07/01 17:57:15.280 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js"}
2023/07/01 17:57:15.280 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/css/main.e6c13ad2.css", "result": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css"}
2023/07/01 17:57:15.280 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css"}
2023/07/01 17:57:15.307 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/css/main.e6c13ad2.css.map", "result": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css.map"}
2023/07/01 17:57:15.307 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/css/main.e6c13ad2.css.map"}
2023/07/01 17:57:15.381 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/static/js/main.4586af2c.js.map", "result": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js.map"}
2023/07/01 17:57:15.381 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/static/js/main.4586af2c.js.map"}
2023/07/01 17:57:15.484 DEBUG   http.handlers.file_server       sanitized path join     {"site_root": "/home/wxy/www/sms-server/build", "request_path": "/favicon.ico", "result": "/home/wxy/www/sms-server/build/favicon.ico"}
2023/07/01 17:57:15.484 DEBUG   http.handlers.file_server       opening file    {"filename": "/home/wxy/www/sms-server/build/favicon.ico"}

next is caddyfile

{
    auto_https off
    debug
}
10.1.0.199:80 {
    handle_path /sms-srv/* {
        root * /home/wxy/www/sms-server/build
        file_server
        try_files {path} /index.html
    }

    root * /home/wxy/www/sms-server/build
    file_server
    try_files {path} /index.html
}

when i request http://10.1.0.199/sms-srv the response is

You need to enable JavaScript to run this app

. or

 null page.

when i request http://10.1.0.199 it no problem

3. Caddy version:

v2.6.4

4. How I installed and ran Caddy:

a. System environment:

ubuntu

b. Command:

apt install

i can’t fix that. OMG!!!

/sms-srv/* will not match /sms-srv because it’s missing a trailing slash. Try /sms-srv* instead.

it doesn’t work either.
the response is

You need to enable JavaScript to run this app

but when i get 10.1.0.199, it worked well

See this article:

Make sure to configure your app with basePath or whatever. It needs to generate URLs in your HTML with the path you’re trying to proxy to.

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