简体   繁体   中英

Dynamic routes not working in React with Caddy

I have a React Application. I am using some routes that receives parameters in the URL (by GET), for example myapp.com/products/1 that works pretty good in local enviroment but no in my CentOS server. I have to mention that I am using npm run build to generate the static files.

For other side, I have running Caddy as HTTP server in the CentOS server, there I have problem only with the routes that includes parameters, so now am wondering if caddy have something to be with this issue.

Here the React people say:

If you're using Apache, you need to create a .htaccess file in the public folder that looks like this:

 Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.html [QSA,L]

So, how can I do that in Caddy. I have currently these lines for the site:

mysite.com {
   root PathToProject/build/
   log logs/pagelog.log
}

What is missing in order to can use parameters in the URL?

I have this config in my Caddyfile

rewrite {
  if    {path} not_match ^\/0.0.0.0
  to    {path} {path}/ /?_url={uri}
}

See if that helps, it took care of my routing issue (similar to what u have mentioned) for React App.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM