-2

I have the following scripts object in my package.json:

"scripts": {
    "build-css": "node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss",
    "watch-css": "npm run build-css && node-sass-chokidar --include-path ./node_modules ./src/scss -o ./src/scss --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    "build-js": "react-scripts build",
    "build": "npm-run-all build-css build-js",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }

My application is starting with http://localhost:3000 on my local machine, and on my NGINX with the URL that I have configured.

I would like to have a path added to both URLs like this

http://localhost:3000/subpath/ or for my server {url}/subpath/

Is there an easy way to do it? Some solutions I find looked unnecessarily difficult.

yemerra
  • 1,352
  • 4
  • 19
  • 44
  • How about making a mapping for the host in /etc/hosts? – Shubham Jain Nov 16 '19 at 13:07
  • @ShubhamJain Could you please explain it in more detail? sorry I am ignorant about this topic. – yemerra Nov 16 '19 at 13:09
  • so in your `/etc/hosts` file you can add mapping for your localhost. Something like `127.0.0.1 shubham.test.com`. What this does is now I can open shubham.test.com:3000 to run my server application? Is this something you were expecting or did I understood wrong? – Shubham Jain Nov 16 '19 at 13:11
  • I think this is not what I am looking for. When I start the app with `start` or when I build the app, it does not consider subpath like `/customPath/`. It will always run on the base path like `http://localhost:3000`. I simply always want to start it with a path added to the end like `http://localhost:3000/customPath` – yemerra Nov 16 '19 at 13:15
  • You could route your application to custom route using react router – Shubham Jain Nov 16 '19 at 13:19

1 Answers1

0

You can do is redirect you base route to a custom URL in react router:

<Router history={history}>
  <Redirect from="/" to="customURL"/>
  <Route component={Layout} path="/">
    <Route component={Dashboard} path="customURL"/>
  </Route>
</Router>

This would redirect the base application from / to /customURL.

Let me know if this worked and if this is what were looking for!

Shubham Jain
  • 930
  • 1
  • 14
  • 24