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
The local should be http://localhost:3000/my-app
insted of http://localhost:3000/
Thanks for advance.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With