The Extensions documentation is no longer updated. Read the new Canva API docs here.

Set up a Base URL (with ngrok)

Learn how to set up Base URL with ngrok, an SSH tunneling service.

In the Developer Portal, extensions have a Base URL field. This indicates that the extension must provide the URL of a server that can receive and respond to HTTP requests from Canva. You can use any programming language, framework, or architecture to handle these requests.

This tutorial explains how to set up a Base URL with:

ngrok is a useful tool, but it has inherent security risks, such as someone figuring out the URL of your server and accessing proprietary information. Be mindful of the risks, and if you're working as part of an organization, talk to your IT department.

Step 1: Install Node.js

To check if Node.js is installed, run the following command:

node --version
BASH

You should see something like this:

$ node --version
v14.15.0
BASH

If it's not installed, download it from the official website(opens in a new tab or window).

Step 2: Set up a new project

Create a project with the following structure:

  • my-app
    • src/
      • server.js
    • .env
    • package.json

To create this structure, run the following commands:

mkdir my-app
cd my-app
npm init --yes # yarn init
mkdir src
touch .env src/server.js
BASH

The touch command is not available on Windows. If you're using Windows, create the files manually.

Then copy the following code into the server.js file:

require("dotenv").config();
const express = require("express");
const app = express();
app.use(express.json());
app.use(express.static("public"));
// Routes go here
app.listen(process.env.PORT || 3000);
JAVASCRIPT

This code initializes an Express.js server without any endpoints. The required endpoints depend on the app's extensions and how they're configured.

Step 3: Install the dependencies

Install the following runtime dependencies:

To install these dependencies, run the following command:

npm install express dotenv --save && npm install nodemon --save-dev
# yarn add express dotenv && yarn add nodemon --dev
BASH

Step 4: Start the local server

Copy the following script into the package.json file:

"scripts": {
"start": "nodemon src/server.js"
}
JSON

Then start the local server with the start command:

npm run start
# yarn start
BASH

The local server becomes available at http://localhost:3000(opens in a new tab or window).

Step 5: Expose the local server

For Canva to send requests to a local server, it needs to be exposed via a publicly available URL. One of the easiest ways to do this is with ngrok.

ngrok is a free tool that creates a secure tunnel to a local server. You can create tunnels without an account, but the tunnels expire after a few hours of activity. If you have an account, the tunnels don't expire.

To install ngrok, run the following command:

npm install ngrok --global
BASH

To verify that ngrok is installed, run the following command:

ngrok version
BASH

You should see something like this:

$ ngrok version
ngrok version 2.3.35
BASH

If you run into any errors, refer to the official installation instructions(opens in a new tab or window).

To start an ngrok tunnel, run the following command in a separate terminal while the local server is still running:

ngrok http 3000
BASH

This command assumes the port of the local server is 3000.

After running this command, ngrok provides a HTTPS-enabled URL that can receive requests from Canva. You can enter this URL into the extension's Base URL field.

Example

src/server.js

require("dotenv").config();
const express = require("express");
const app = express();
app.use(express.json());
app.use(express.static("public"));
// Routes go here
app.listen(process.env.PORT || 3000);
JAVASCRIPT

.env

# add environment variables here
BASH

package.json

{
"name": "my-app",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "nodemon src/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1"
},
"devDependencies": {
"nodemon": "^2.0.6"
}
}
JSON