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
.nvmrcfile, so if you use nvm you can runnvm installand thennvm 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.
Option 1: degit (recommended)
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
-
In the project folder, run:
npm cinpm installalso works, butnpm ciinstalls the exact locked versions. -
Check that the install created a
.envfile. Apostinstallscript copies.env.exampleto.envif.envdoes 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
| Variable | Used by | Description |
|---|---|---|
HOOTSUITE_APP_ID | Frontend and backend | Your 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_PORT | Dev server and backend | Port of the frontend dev server. Default 8080. |
BACKEND_PORT | Example backend | Port of the example backend. Default 3001. |
BACKEND_HOST | Frontend | Base URL that useBackend() calls. Use an HTTPS URL for any bundle you upload. |
EXTERNAL_API_BASE_URL | Example backend | Base URL of your provider's API, for example https://api.todoist.com/api/v1. |
ALLOWED_ORIGINS | Example backend | Optional. 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_ENABLED | Dev server | TRUE enables hot module replacement. .env.example ships with FALSE. |
HOOTSUITE_DASHBOARD_URL | Frontend and dev server | Origin 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
-
Start the frontend and the example backend together:
npm start -
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.
- Frontend:
-
Open
https://localhost:8080in 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
| Script | Description |
|---|---|
npm start | Start the frontend dev server and the example backend. |
npm run build | Build the production bundle, dist/app.js. |
npm run build:dev | Build a development bundle with source maps. |
npm test | Run the unit tests with the Node.js test runner. |
npm run lint:types | Type-check with TypeScript. |
npm run format | Format code with Prettier. |
npm run format:check | Check formatting with Prettier. Some template files are not formatted yet, so run npm run format once if it reports them. |
npm run storybook | Open Storybook on port 6006. |
npm run build-storybook | Build a static Storybook. |
The template does not include ESLint or a lint script. Add ESLint yourself if you want linting.
Add a page
- Add a path to the
Pathsenum insrc/routes/routes.tsx. - Register a route in the
childrenarray. Wrap the element inProtectedRouteif the page requires a connected provider account.ProtectedRoutesends the user to the Authorize page wheneverisAuthenticatedisfalse, including when they need to reconnect. - Implement the page under
src/components/pages/, using components fromhootsuite-bento.
export enum Paths {
ENTRYPOINT = '/',
AUTHORIZE = '/authorize',
HOME = '/home',
ERRORS = '/error',
TASKS = '/tasks',
}