This article provides a complete guide to create and host a React application on Square Cloud.
my-react-app
is the name of your new project. You can replace my-react-app
with any desired name for your project.
create-react-app
is a package available in the npm registry that sets up a new React project automatically. It takes care of all the initial setup, such as creating the project directory, installing necessary dependencies, and configuring basic files.
serve
. This library is a static server that can serve your React project after it has been built.
serve
library, navigate to your project directory in the terminal and run the following command:
14.2.3
of the serve
library. If you want to install the latest version, you can omit the @14.2.3
.
serve
library, you need to configure your project’s startup script to use serve
. To do this, open your project’s package.json
file and add a new script called start:prod
:
start:prod
script, serve -s build -l 80
does the following:
serve
: This is the command to start the serve
server.-s build
: The -s
option serves the build
directory in single-page application mode. This means all not-found requests will be redirected to index.html
. The build
directory is created when you run npm run build
.-l 80
: The -l
option followed by 80
tells serve
to listen on port 80. Port 80 is the default port for HTTP traffic.npm run start:prod
command. This command first builds your React project and then serves the built files using serve
on port 80.
START
field is essential to customize the startup command. If you want to build and start your application on Square Cloud, configure the START
field as follows:
package.json
:
mysite.com
) instead of the default URL https://mysite.squareweb.app/
, you need the Standard plan or higher. The subdomain is defined by the SUBDOMAIN field in the configuration file. See: How to set up your custom domain..env
file.