Adding a base path
important
- This feature is only available for core versions >= 3.9
- This is applicable only to self hosted cores
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 of the core APIs. To do this, you will have to make changes to the core's config as well as to the backend SDK's init
function call.
Let's take an example where we want the core to be located on http://localhost:3567/some-prefix
. This implies that all APIs exposed by the core will be on http://localhost:3567/some-prefix/*
.
#
Step 1) Core config change- With Docker
- Without Docker
docker run \
-p 3567:3567 \
-e BASE_PATH="/some-prefix" \
-d registry.supertokens.io/supertokens/supertokens-<db_name>
# You need to add the following to the config.yaml file.
# The file path can be found by running the "supertokens --help" command
base_path: "/some-prefix"
#
Step 2) Backend SDK changes- NodeJS
- GoLang
- Python
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
import supertokens from "supertokens-node";
supertokens.init({
supertokens: {
connectionURI: "http://localhost:3567/some-prefix",
// ...
},
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "...",
},
recipeList: [/* ... */ ]
});
import "github.com/supertokens/supertokens-golang/supertokens"
func main() {
supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "http://localhost:3567/some-prefix",
},
})
}
from supertokens_python import init, InputAppInfo, SupertokensConfig
init(
app_info=InputAppInfo(api_domain="...", app_name="...", website_domain="..."),
supertokens_config=SupertokensConfig(
connection_uri='http://localhost:3567/some-prefix',
),
framework='...',
recipe_list=[
#...
]
)
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"