Skip to main content

Get Started with the Template

The Embedded app template is a React and TypeScript project that already handles the host handshake, authorization, routing, and the Bento design system. It also includes a minimal example backend. This page takes you from an empty folder to a running dev server.


Prerequisites​

  • Node.js 20.19 or later, or 22.12 or later. This is the minimum Storybook 10 requires. The template includes an .nvmrc file, so if you use nvm you can run nvm install and then nvm use.
  • npm 10 or later.
  • Access to the public npm registry, https://registry.npmjs.org. You do not need any Hootsuite credentials to install the template.

Step 1: Get the template​

The template is in the samples/embedded-apps-template folder of the hootsuite/public-api-docs repository on GitHub, on the main branch. Copy that folder into a new project folder with one of the options below. Both use my-app as the folder name; replace it with the name of your project.

degit copies only the template folder, without the Git history of the repository:

npx degit hootsuite/public-api-docs/samples/embedded-apps-template my-app
cd my-app

The new folder is not a Git repository. Run git init in it if you want to put your app under version control.

Option 2: Git sparse checkout​

If you cannot use npx, clone the repository without downloading its files, check out only the template folder, and copy it into your project folder:

git clone --depth 1 --branch main --filter=blob:none --sparse https://github.com/hootsuite/public-api-docs.git
git -C public-api-docs sparse-checkout set samples/embedded-apps-template
cp -R public-api-docs/samples/embedded-apps-template my-app
rm -rf public-api-docs
cd my-app

Copying the folder out keeps your app separate from the history of the documentation repository.


Step 2: Install dependencies​

  1. In the project folder, run:

    npm ci

    npm install also works, but npm ci installs the exact locked versions.

  2. Check that the install created a .env file. A postinstall script copies .env.example to .env if .env does not exist yet.

The Bento design system is included in the template as the file resources/bento/hootsuite-bento-0.0.5.tgz, declared as a local dependency named hootsuite-bento. It installs without a registry or credentials. All other dependencies come from the public npm registry. Bento declares React 17 or 18 as a peer dependency, and the template uses React 18.


Step 3: Configure .env​

Open .env and set your values. The file starts as a copy of .env.example, with HOOTSUITE_APP_ID, EXTERNAL_API_BASE_URL and ALLOWED_ORIGINS empty:

# Your Hootsuite App ID (obtained from the developer portal)
HOOTSUITE_APP_ID=<YOUR_APP_ID>

# Frontend development server port
FRONTEND_PORT=8080

# Example backend port
BACKEND_PORT=3001

# URL of your backend, used by the iframe (change to your production HTTPS URL before deploying)
BACKEND_HOST=http://localhost:3001

# Base URL of your external provider's API, used by the example backend route
EXTERNAL_API_BASE_URL=<YOUR_PROVIDER_API_BASE_URL>

# Origins your backend accepts requests from, separated by commas (optional).
# Leave it empty to use the defaults: https://<HOOTSUITE_APP_ID>.hootsuite-apps.com,
# plus https://localhost:<FRONTEND_PORT> unless NODE_ENV=production.
# When set, it replaces the defaults exactly, so list every origin you need.
# Production example: ALLOWED_ORIGINS=https://<HOOTSUITE_APP_ID>.hootsuite-apps.com
# Changing .env requires stopping and restarting `npm start`.
ALLOWED_ORIGINS=

# Enable Hot Module Replacement (set to TRUE for development)
HMR_ENABLED=FALSE

# Hootsuite Dashboard URL (only postMessage events from this origin are accepted)
HOOTSUITE_DASHBOARD_URL=https://hootsuite.com
VariableUsed byDescription
HOOTSUITE_APP_IDFrontend and backendYour app ID from the Developer Portal. By default the backend uses it to allow CORS from https://<HOOTSUITE_APP_ID>.hootsuite-apps.com. If you set ALLOWED_ORIGINS, the backend does not use HOOTSUITE_APP_ID for CORS. See Create and configure the app.
FRONTEND_PORTDev server and backendPort of the frontend dev server. Default 8080.
BACKEND_PORTExample backendPort of the example backend. Default 3001.
BACKEND_HOSTFrontendBase URL that useBackend() calls. Use an HTTPS URL for any bundle you upload.
EXTERNAL_API_BASE_URLExample backendBase URL of your provider's API, for example https://api.todoist.com/api/v1.
ALLOWED_ORIGINSExample backendOptional. Comma-separated origins the backend accepts requests from (CORS). When set, it replaces the defaults exactly (https://<HOOTSUITE_APP_ID>.hootsuite-apps.com, plus https://localhost:<FRONTEND_PORT> when NODE_ENV is not production): nothing is added and NODE_ENV does not change it. A trailing slash or a path is ignored. See Call your own backend.
HMR_ENABLEDDev serverTRUE enables hot module replacement. .env.example ships with FALSE.
HOOTSUITE_DASHBOARD_URLFrontend and dev serverOrigin of the Hootsuite dashboard. The bridge accepts messages only from this exact origin and sends messages only to it.

Step 4: Run the dev server​

  1. Start the frontend and the example backend together:

    npm start
  2. Wait for the summary:

    • Frontend: https://localhost:8080, served over HTTPS with a self-signed certificate.
    • Backend: http://localhost:3001, with a health check at /health.
  3. Open https://localhost:8080 in a separate browser tab and accept the certificate warning. If Hootsuite is already open, reload it afterwards.

The backend restarts automatically when you edit files in server/; this does not reload .env, so restart npm start after changing it. When HMR_ENABLED is FALSE, webpack still rebuilds the frontend when you save a file; close and reopen the app in Hootsuite to load the new version.

At this point the app runs locally, but it only works inside Hootsuite, because it waits for the host handshake. Continue with Create and configure the app and then Develop and test.


Project structure​

├── src/ # Frontend React app
│ ├── index.tsx # Entry point
│ ├── App.tsx # Theme, error boundary, router
│ ├── api/ # useBackend(): calls your backend, renews the token on 401
│ ├── components/pages/ # Entrypoint, Authorize (Connect and Reconnect), Home, Error pages
│ ├── context/ # AppConnector, HootsuiteContextProvider, useHootsuite, token helpers
│ ├── routes/ # Route tree and ProtectedRoute
│ └── styles/ # CSS
├── server/ # Example backend
│ ├── server.ts # Express setup, CORS, health check
│ ├── routes/api.ts # Example route that calls your provider
│ └── middleware/auth.ts # requireBearer: reads the access token
├── scripts/ # start.ts and copy_env.ts
├── public/index.html # HTML page used by the dev server
├── resources/bento/ # hootsuite-bento package
├── resources/storybook/ # Storybook stories for Bento components
├── LICENSE.md # License terms
└── webpack.config.ts # Builds a single dist/app.js

Unit tests sit next to the code they test, in *.test.ts files.

Two import aliases are configured: @/ maps to src/, and @components/ maps to src/components/.

Available scripts​

ScriptDescription
npm startStart the frontend dev server and the example backend.
npm run buildBuild the production bundle, dist/app.js.
npm run build:devBuild a development bundle with source maps.
npm testRun the unit tests with the Node.js test runner.
npm run lint:typesType-check with TypeScript.
npm run formatFormat code with Prettier.
npm run format:checkCheck formatting with Prettier. Some template files are not formatted yet, so run npm run format once if it reports them.
npm run storybookOpen Storybook on port 6006.
npm run build-storybookBuild a static Storybook.

The template does not include ESLint or a lint script. Add ESLint yourself if you want linting.

Add a page​

  1. Add a path to the Paths enum in src/routes/routes.tsx.
  2. Register a route in the children array. Wrap the element in ProtectedRoute if the page requires a connected provider account. ProtectedRoute sends the user to the Authorize page whenever isAuthenticated is false, including when they need to reconnect.
  3. Implement the page under src/components/pages/, using components from hootsuite-bento.
export enum Paths {
ENTRYPOINT = '/',
AUTHORIZE = '/authorize',
HOME = '/home',
ERRORS = '/error',
TASKS = '/tasks',
}

Next step​

Create and configure the app in the Developer Portal.