Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to serve a react app on diffrent url on `npm start`

By default in a react app , npm start serve the url in http://localhost:3000/. I want to serve the application in a different url such as http://localhost:3000/my-app in development mode. How can I do it?

I don't want to change the app directory. Instead of serving the app on localhost:3000 I want it to serve at localhost:3000/my-app url. Which means localhost:3000/my-app will be the default url.Here's the reference image

enter image description here

The local should be http://localhost:3000/my-app insted of http://localhost:3000/

Thanks for advance.

like image 955
Kallol Pratim Avatar asked Aug 30 '25 16:08

Kallol Pratim


1 Answers

In windows, you can change all the parts of the url from package.json. just modify the script, start for this case, to be like this

"start": "set PUBLIC_URL=myapp&&set HOST=DOMAIN-NAME&&set PORT=AppPort&&react-scripts start"

This will effectively configure npm to open your browser using the url

http://DOMAIN-NAME:AppPort/myapp

Also you can configure HTTPS protocol and certificate as well

"start": "set PUBLIC_URL=myapp&&set HTTPS=true&&set SSL_CRT_FILE=[path to certificate]&&set SSL_KEY_FILE=[path to key file]&&set HOST=DOMAIN-NAME&&set PORT=AppPort&&react-scripts start"

which will be open in

https://DOMAIN-NAME:AppPort/myapp

the solution for other OS will be similar

like image 156
Ahmed Bahtity Avatar answered Sep 02 '25 05:09

Ahmed Bahtity