Search code examples
reactjscreate-react-app

create-react-app and url base path for the development server


during development, I'd like to use an already existing test server, this server uses apache, so I basically used mod_proxy to proxy it to a subdirectory of my server, let's say http://myserver/myreactapp/ Problem is, I didnt find a way to tell the development server that the js shouldnt be in

<script type="text/javascript" src="/static/js/bundle.js"></script></body>

but in

<script type="text/javascript" src="/myreactapp/static/js/bundle.js"></script></body>

or more logically, in a relative path. I found this option for the build, but not the development server. what is a good way of achieving that ?


Solution

  • If you use nginx, you can use alias like this:

    location /static/ {
      alias /myreactapp/static/;
    }
    

    If you use apache, the alias syntax is:

    Alias "/static" "/myreactapp/static"