This tutorial walks you through creating a Forge app that displays custom UI content on a Confluence page. Using custom UI, you can define your own user interface using static resources, such as HTML, CSS, JavaScript, and images. The Forge platform hosts your static resources, enabling your app to display custom UI on Atlassian products. Custom UI apps inherit modern security features to ensure high trust between Atlassian, developers, and users.
At the end of this tutorial, you’ll have created a Forge app in Confluence that uses custom UI to display customized UI content.
When you create a new app, Forge will prompt you to set a default environment. In this
tutorial we use the development
environment as our default. See Default environments for more information.
Forge also provides a staging
and production
environments where you can deploy your app. See
Environments and versions for more information.
This tutorial assumes you're already familiar with the basics of Forge development. If this is your first time using Forge, see Getting started first.
To complete this tutorial, you need the latest version of Forge CLI. To update your CLI version, run npm install -g @forge/cli@latest
on the command line.
Forge apps can't be viewed by anonymous users. To use a Forge app, you must be logged in to Confluence.
An Atlassian cloud developer site lets you install and test your app on Confluence and Jira products set up for you. If you don't have one yet, set it up now:
You can install your app to multiple Atlassian sites. However, app data won't be shared between separate Atlassian sites, products, or Forge environments.
The limits on the numbers of users you can create are as follows:
The Atlassian Marketplace doesn't currently support cross-product apps. If your app supports multiple products, you can publish two separate listings on the Marketplace, but your app won't be able to make API calls across different products and instances/installations.
This app displays custom content in a content byline item on a Confluence page using custom UI.
Navigate to the directory where you want to create the app. A new directory with the app’s name will be created there.
Create your app by running:
1 2forge create
Enter a name for your app. For example, hello-world-custom-ui.
Select the Custom UI category.
Select the Confluence product.
Select the confluence-content-byline template.
Change to the app subdirectory to see the app files.
1 2cd hello-world-custom-ui
The confluence-byline-item-custom-ui
template has React JS for the static frontend and Node JS
for the FaaS backend. The template contains the following structure:
1 2hello-world-custom-ui |-- src | `-- index.js |-- static | `-- hello-world | `-- src | `-- index.js | `-- App.js | `-- public | `-- index.html | `-- package.json | `-- package-lock.json |-- manifest.yml |-- package.json |-- package-lock.json `-- README.md
Let’s have a look at what these files are:
src/index.js
: Where you write your FaaS backend functions.static
: Where you write and include your static frontend assets.manifest.yml
: Describes your app. It contains the name and ID of your app, along with the modules
it uses. This app displays a content byline app on all Confluence pages and has a resource that
provides the content of your custom UI for the app.package.json
: The app’s Node.js metadata. See the
Node documentationfor more information.package-lock.json
: Records the version of the app’s dependencies.README.md
: Information about the app. We recommend updating this as you change the behavior of
the app.This app displays content in a Confluence byline item using the confluence:contentBylineItem
module. Confluence shows the title of the confluence:contentBylineItem
below the title of the
content. Let's change the title to include your name.
manifest.yml
file.title
entry under the confluence:contentBylineItem
module.title
from hello-world-app
to Hello World from <your name>
.
For example, Hello World from Emma Richards.Your manifest.yml
file should look like the following, with your values for the title and app ID.
1 2modules: confluence:contentBylineItem: - key: hello-world-content-byline resource: main resolver: function: resolver title: Hello World from Emma Richards function: - key: resolver handler: index.handler resources: - key: main path: static/hello-world/build app: id: '<your app id>'
In this template, we're using create-react-app to
generate the static content that your app will be using. This library is generally used to create
new single-page React applications. We'll use the library to generate a simple Hello, world!
message in a Confluence content byline item by serving a single-page React app.
You need to install and build these resources so your app can use them. Follow these steps to build the resources for your app:
Navigate to the static/hello-world
directory.
Install the needed dependencies:
1 2npm install
Build the assets:
1 2npm run build
Navigate back to the top-level directory of your app.
Any time you make changes to your app code, rebuild the static frontend as prescribed above
and then run a deploy using the forge deploy
command. This command compiles your FaaS code,
and deploys your functions and static assets to the Atlassian cloud.
To install your app on a new site, run the forge install
command. Once the app is installed on a
site, it will automatically pick up all minor app deployments, which means you don't need to run the
install command again. A minor deployment includes any change that doesn't modify app permissions
in the manifest.
Navigate to the app's top-level directory and deploy your app by running:
1 2forge deploy
Install your app by running:
1 2forge install
Select your Atlassian product using the arrow keys and press the enter key.
Enter the URL for your development site. For example, example.atlassian.net. View a list of your active sites at Atlassian administration.
Once the successful installation message appears, your app is installed and ready
to use on the specified site.
You can always delete your app from the site by running the forge uninstall
command.
Running the forge install
command only installs your app onto the selected product.
To install onto multiple products, repeat these steps again, selecting another product each time.
Note that the Atlassian Marketplace
does not support cross-product apps yet.
You must run forge deploy
before running forge install
in any of the Forge environments.
With your app installed, it’s time to see the app on a page.
The app should display on the page with the content of your custom UI, like the image below.
While your app is deployed to either a development or staging environment, (DEVELOPMENT)
or
(STAGING)
will appear in your app title. This suffix is removed once you've
deployed your app to production.
By now, you can now see your app displaying the message Hello, world!
in the Confluence content
byline item. This is the product of setting up your static assets & using a resolver function to dynamically
generate the message.
Follow these steps to modify the static assets:
Navigate to the static/hello-world/src
directory.
Open the App.js
file. The default content of the file is shown below:
1 2import React, { useEffect, useState } from 'react'; import { invoke } from '@forge/bridge'; function App() { const [data, setData] = useState(null); useEffect(() => { invoke('getText', { example: 'my-invoke-variable' }).then(setData); }, []); return ( <div> {data ? data : 'Loading...'} </div> ); } export default App;
Modify the content of the file.
Rebuild the static assets for you custom UI frontend by running the npm run build
command.
Navigate to the app's top-level directory and start a tunnel for your app by running:
1 2forge tunnel
You can see your changes by refreshing the page that your app is on.
Redeploy your app by running the forge deploy
command.
Follow these steps to modify the value of the message returned by your FaaS backend resolver:
Navigate to the src
directory.
Open the index.js
file. The default content of the file is shown below:
1 2import Resolver from '@forge/resolver'; const resolver = new Resolver(); resolver.define('getText', (req) => { console.log(req); return 'Hello, world!'; }); export const handler = resolver.getDefinitions();
Modify the content of the file.
Navigate to the app's top-level directory and start a tunnel for your app by running:
1 2forge tunnel
You can see your changes by refreshing the page that your app is on.
Redeploy your app by running the forge deploy
command.
See the reference pages for more information on what you can do with Forge.
Rate this page: