Local development setup
Learn how to set up a local development environment to edit the contents of a React app using the AEM Universal Editor.
Prerequisites
The following are required to follow this tutorial:
-
Basic HTML and JavaScript skills.
-
The following tools must be installed locally:
- Node.js
- Git
- An IDE or code editor, such as Visual Studio Code
-
Download and install the following:
- AEM as a Cloud Service SDK: It contains the Quickstart Jar used to run AEM Author and Publish locally for development purposes.
- Universal Editor service: A local copy of the Universal Editor service, it has a subset of features and can be downloaded from the Software Distribution portal.
- local-ssl-proxy: A simple local SSL HTTP proxy using a self-signed certificate for local development. The AEM Universal Editor requires the HTTPS URL of the React app to load it in the editor.
Local setup
Follow the steps below to set up the local development environment:
AEM SDK
To provide the contents for the WKND Teams React app, install the following packages in the local AEM SDK.
-
WKND Teams - Content Package: Contains the Content Fragment Models, Content Fragments, and persisted GraphQL queries.
-
WKND Teams - Config Package: Contains the Cross-Origin Resource Sharing (CORS) and Token Authentication Handler configurations. The CORS facilitates non-AEM web properties to make browser-based client-side calls to AEM’s GraphQL APIs and the Token Authentication Handler is used to authenticate each request to AEM.
React app
To set up the WKND Teams React app, follow the steps below:
-
Clone the WKND Teams React app from the
basic-tutorial
solution branch.code language-bash $ git clone -b solution/basic-tutorial git@github.com:adobe/aem-guides-wknd-graphql.git
-
Navigate to the
basic-tutorial
directory and open it in your code editor.code language-bash $ cd aem-guides-wknd-graphql/basic-tutorial $ code .
-
Install the dependencies and start the React app.
code language-bash $ npm install $ npm start
-
Open the WKND Teams React app in your browser at http://localhost:3000. It displays a list of team members and their details. The content for the React app is provided by the local AEM SDK using GraphQL APIs (
/graphql/execute.json/my-project/all-teams
), which you can verify using the browser’s network tab.
Universal Editor Service
To set up the local Universal Editor service, follow the steps below:
-
Download the latest version of the Universal Editor service from the Software Distribution Portal.
-
Extract the downloaded zip file and copy the
universal-editor-service.cjs
file to a new directory nameduniversal-editor-service
.code language-bash $ unzip universal-editor-service-vproduction-<version>.zip $ mkdir universal-editor-service $ cp universal-editor-service.cjs universal-editor-service
-
Create
.env
file in theuniversal-editor-service
directory and add the following environment variables:code language-bash # The port on which the Universal Editor service runs EXPRESS_PORT=8000 # Disable SSL verification NODE_TLS_REJECT_UNAUTHORIZED=0
-
Start the local Universal Editor service.
code language-bash $ cd universal-editor-service $ node universal-editor-service.cjs
The above command starts the Universal Editor service on port 8000
and you should see the following output:
Either no private key or certificate was set. Starting as HTTP server
Universal Editor Service listening on port 8000 as HTTP Server
Local SSL HTTP proxy
The AEM Universal Editor requires the React app to be served over HTTPS. Let’s set up a local SSL HTTP proxy that uses a self-signed certificate for local development.
Follow the steps below to set up the local SSL HTTP proxy and serve the AEM SDK and Universal Editor service over HTTPS:
-
Install the
local-ssl-proxy
package globally.code language-bash $ npm install -g local-ssl-proxy
-
Start two instances of the local SSL HTTP proxy for the following services:
- AEM SDK local SSL HTTP proxy on port
8443
. - Universal Editor service local SSL HTTP proxy on port
8001
.
code language-bash # AEM SDK local SSL HTTP proxy on port 8443 $ local-ssl-proxy --source 8443 --target 4502 # Universal Editor service local SSL HTTP proxy on port 8001 $ local-ssl-proxy --source 8001 --target 8000
- AEM SDK local SSL HTTP proxy on port
Update the React app to use HTTPS
To enable HTTPS for the WKND Teams React app, follow the steps below:
-
Stop the React by pressing
Ctrl + C
in the terminal. -
Update the
package.json
file to include theHTTPS=true
environment variable in thestart
script.code language-json "scripts": { "start": "HTTPS=true react-scripts start", ... }
-
Update the
REACT_APP_HOST_URI
in the.env.development
file to use the HTTPS protocol and the local SSL HTTP proxy port of the AEM SDK.code language-bash REACT_APP_HOST_URI=https://localhost:8443 ...
-
Update the
../src/proxy/setupProxy.auth.basic.js
file to use relaxed SSL settings usingsecure: false
option.code language-javascript ... module.exports = function(app) { app.use( ['/content', '/graphql'], createProxyMiddleware({ target: REACT_APP_HOST_URI, changeOrigin: true, secure: false, // Ignore SSL certificate errors // pass in credentials when developing against an Author environment auth: `${REACT_APP_BASIC_AUTH_USER}:${REACT_APP_BASIC_AUTH_PASS}` }) ); };
-
Start the React app.
code language-bash $ npm start
Verify the setup
After setting up the local development environment using the above steps, let’s verify the setup.
Local verification
Make sure that the following services are running locally over HTTPS, you may need to accept the security warning in the browser for the self-signed certificate:
- WKND Teams React app on https://localhost:3000
- AEM SDK on https://localhost:8443
- Universal Editor service on https://localhost:8001
Load WKND Teams React app in Universal Editor
Let’s load the WKND Teams React app in the Universal Editor to verify the setup:
-
Open the Universal Editor https://experience.adobe.com/#/aem/editor in your browser. If prompted, log in using your Adobe ID.
-
Enter the WKND Teams React app URL in the Universal Editor’s Site URL input field and click
Open
. -
The WKND Teams React app loads in the Universal Editor but you cannot edit the content yet. You need to instrument the React app to enable content editing using the Universal Editor.
Next Step
Learn how to instrument the React app to edit the content.