Skip to main content

Adding a base path

Overview

If you cannot add a dedicated (sub) domain for the core and want to expose it to an external network, you may need to add a base path to all the core APIs. To do this, you have to make changes to the core's configuration as well as to the backend SDK's init function call.

Consider an example where the core resides on http://localhost:3567/some-prefix. This implies that all APIs exposed by the core are on http://localhost:3567/some-prefix/*.

Before you start

This page is only relevant if you are self hosting SuperTokens.

The feature is only available for core versions >= 3.9

Steps

1. Change the core configuration

 docker run \
-p 3567:3567 \
// highlight-next-line
-e BASE_PATH="/some-prefix" \
-d registry.supertokens.io/supertokens/supertokens-<db_name>

2. Change the backend SDK initialization

import supertokens from "supertokens-node";

supertokens.init({
supertokens: {
connectionURI: "http://localhost:3567/some-prefix",
// ...
},
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "...",
},
recipeList: [/* ... */ ]
});
note

You can even set different base paths for different core instances:

  • For each of the core's configs you need to supply their base path as mentioned in step 1
  • The connection URI should be something like "<core1-domain>/<core1-basePath>;<core2-domain>/<core2-basePath>;<core2-domain>/<core2-basePath>;". For example, a valid connection URI can be "http://localhost:3567/some-prefix;http://localhost:3567/some-prefix-2"