From 7b303d51883ebec43586c17cc0b15e3928373a6d Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Tue, 1 Oct 2024 10:49:18 +0530 Subject: [PATCH 01/16] Added cross-end dependecy --- boilerplate/backend/node-express/package.json | 3 ++- package-lock.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/boilerplate/backend/node-express/package.json b/boilerplate/backend/node-express/package.json index c4ba073e..19ab6b37 100644 --- a/boilerplate/backend/node-express/package.json +++ b/boilerplate/backend/node-express/package.json @@ -22,7 +22,8 @@ "@types/express": "^4.17.17", "@types/morgan": "^1.9.3", "@types/node": "^16.11.38", - "nodemon": "^2.0.16" + "nodemon": "^2.0.16", + "cross-env": "^7.0.3" }, "keywords": [], "author": "", diff --git a/package-lock.json b/package-lock.json index acdedf18..6d4a71f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "create-supertokens-app", - "version": "0.0.50", + "version": "0.0.51", "license": "Apache-2.0", "dependencies": { "chalk": "^5.0.1", From 5597bfc4c9476da061deaa06c0247809699d1554 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Tue, 1 Oct 2024 10:50:58 +0530 Subject: [PATCH 02/16] express js dynamic ports --- boilerplate/backend/node-express/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/boilerplate/backend/node-express/index.ts b/boilerplate/backend/node-express/index.ts index 26fb1025..b0797e3c 100644 --- a/boilerplate/backend/node-express/index.ts +++ b/boilerplate/backend/node-express/index.ts @@ -43,4 +43,6 @@ app.get("/tenants", async (req, res) => { // returns 401 to the client. app.use(errorHandler()); -app.listen(3001, () => console.log(`API Server listening on port 3001`)); +const port = process.env.PORT || 3001; + +app.listen(port, () => console.log(`API Server listening on port ${port}`)); From 760cbb4e445cc76be1731efce406fcc44117632f Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Wed, 2 Oct 2024 10:56:10 +0530 Subject: [PATCH 03/16] added dynamic port express js --- boilerplate/backend/node-express/config/all_auth.ts | 4 ++-- boilerplate/backend/node-express/config/emailpassword.ts | 4 ++-- boilerplate/backend/node-express/config/multifactorauth.ts | 4 ++-- boilerplate/backend/node-express/config/multitenancy.ts | 4 ++-- boilerplate/backend/node-express/config/passwordless.ts | 4 ++-- boilerplate/backend/node-express/config/thirdparty.ts | 4 ++-- .../backend/node-express/config/thirdpartyemailpassword.ts | 4 ++-- .../backend/node-express/config/thirdpartypasswordless.ts | 4 ++-- boilerplate/backend/node-express/index.ts | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/boilerplate/backend/node-express/config/all_auth.ts b/boilerplate/backend/node-express/config/all_auth.ts index d97f362c..188792d0 100644 --- a/boilerplate/backend/node-express/config/all_auth.ts +++ b/boilerplate/backend/node-express/config/all_auth.ts @@ -7,13 +7,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/emailpassword.ts b/boilerplate/backend/node-express/config/emailpassword.ts index 0c3154f0..b1879648 100644 --- a/boilerplate/backend/node-express/config/emailpassword.ts +++ b/boilerplate/backend/node-express/config/emailpassword.ts @@ -5,13 +5,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/multifactorauth.ts b/boilerplate/backend/node-express/config/multifactorauth.ts index 7146fbbd..7dfda943 100644 --- a/boilerplate/backend/node-express/config/multifactorauth.ts +++ b/boilerplate/backend/node-express/config/multifactorauth.ts @@ -10,13 +10,13 @@ import EmailVerification from "supertokens-node/recipe/emailverification"; import TOTP from "supertokens-node/recipe/totp"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/multitenancy.ts b/boilerplate/backend/node-express/config/multitenancy.ts index e40dac71..dab320b9 100644 --- a/boilerplate/backend/node-express/config/multitenancy.ts +++ b/boilerplate/backend/node-express/config/multitenancy.ts @@ -7,13 +7,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/passwordless.ts b/boilerplate/backend/node-express/config/passwordless.ts index fb012cdc..8f0dc2e3 100644 --- a/boilerplate/backend/node-express/config/passwordless.ts +++ b/boilerplate/backend/node-express/config/passwordless.ts @@ -5,13 +5,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/thirdparty.ts b/boilerplate/backend/node-express/config/thirdparty.ts index 0b44fb2e..6374ea22 100644 --- a/boilerplate/backend/node-express/config/thirdparty.ts +++ b/boilerplate/backend/node-express/config/thirdparty.ts @@ -5,13 +5,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts b/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts index 2527c22f..b495a612 100644 --- a/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts +++ b/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts @@ -6,13 +6,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/thirdpartypasswordless.ts b/boilerplate/backend/node-express/config/thirdpartypasswordless.ts index 5401f0d9..778cc138 100644 --- a/boilerplate/backend/node-express/config/thirdpartypasswordless.ts +++ b/boilerplate/backend/node-express/config/thirdpartypasswordless.ts @@ -6,13 +6,13 @@ import Dashboard from "supertokens-node/recipe/dashboard"; import UserRoles from "supertokens-node/recipe/userroles"; export function getApiDomain() { - const apiPort = process.env.REACT_APP_API_PORT || 3001; + const apiPort = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; return apiUrl; } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/index.ts b/boilerplate/backend/node-express/index.ts index b0797e3c..b0b15dec 100644 --- a/boilerplate/backend/node-express/index.ts +++ b/boilerplate/backend/node-express/index.ts @@ -43,6 +43,6 @@ app.get("/tenants", async (req, res) => { // returns 401 to the client. app.use(errorHandler()); -const port = process.env.PORT || 3001; +const port = process.env.VITE_API_PORT || 3001; app.listen(port, () => console.log(`API Server listening on port ${port}`)); From f000539d8ee1705e930f478d1cd7ac9339fe2c79 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Wed, 2 Oct 2024 10:56:31 +0530 Subject: [PATCH 04/16] dynamic port vuejs --- boilerplate/frontend/vue-prebuilt/vite.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boilerplate/frontend/vue-prebuilt/vite.config.ts b/boilerplate/frontend/vue-prebuilt/vite.config.ts index 83dd9156..7b4ea494 100644 --- a/boilerplate/frontend/vue-prebuilt/vite.config.ts +++ b/boilerplate/frontend/vue-prebuilt/vite.config.ts @@ -7,7 +7,7 @@ import vueJsx from "@vitejs/plugin-vue-jsx"; // https://vitejs.dev/config/ export default defineConfig({ server: { - port: 3000, + port: parseInt(process.env.VITE_APP_PORT || "3000"), host: "localhost", open: "/", }, From b224283c5d699ca94ca3139603266908649c2366 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Wed, 2 Oct 2024 12:20:20 +0530 Subject: [PATCH 05/16] vue appinfo config change to support port --- boilerplate/frontend/vue-prebuilt/config/all_auth.ts | 9 ++++++--- .../frontend/vue-prebuilt/config/emailpassword.ts | 9 ++++++--- .../frontend/vue-prebuilt/config/multifactorauth.ts | 9 ++++++--- boilerplate/frontend/vue-prebuilt/config/passwordless.ts | 9 ++++++--- boilerplate/frontend/vue-prebuilt/config/thirdparty.ts | 9 ++++++--- .../vue-prebuilt/config/thirdpartyemailpassword.ts | 9 ++++++--- .../vue-prebuilt/config/thirdpartypasswordless.ts | 9 ++++++--- 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/boilerplate/frontend/vue-prebuilt/config/all_auth.ts b/boilerplate/frontend/vue-prebuilt/config/all_auth.ts index 23d7e11c..c175dd4c 100644 --- a/boilerplate/frontend/vue-prebuilt/config/all_auth.ts +++ b/boilerplate/frontend/vue-prebuilt/config/all_auth.ts @@ -1,11 +1,14 @@ import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -32,7 +35,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [Session.init()], }); diff --git a/boilerplate/frontend/vue-prebuilt/config/emailpassword.ts b/boilerplate/frontend/vue-prebuilt/config/emailpassword.ts index 2c004cff..06e3064f 100644 --- a/boilerplate/frontend/vue-prebuilt/config/emailpassword.ts +++ b/boilerplate/frontend/vue-prebuilt/config/emailpassword.ts @@ -1,11 +1,14 @@ import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -19,7 +22,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [Session.init()], }); diff --git a/boilerplate/frontend/vue-prebuilt/config/multifactorauth.ts b/boilerplate/frontend/vue-prebuilt/config/multifactorauth.ts index a30afb54..b028ab50 100644 --- a/boilerplate/frontend/vue-prebuilt/config/multifactorauth.ts +++ b/boilerplate/frontend/vue-prebuilt/config/multifactorauth.ts @@ -3,11 +3,14 @@ import Session from "supertokens-web-js/recipe/session"; import EmailVerification from "supertokens-web-js/recipe/emailverification"; import MultiFactorAuth from "supertokens-web-js/recipe/multifactorauth"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -41,7 +44,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [ Session.init(), diff --git a/boilerplate/frontend/vue-prebuilt/config/passwordless.ts b/boilerplate/frontend/vue-prebuilt/config/passwordless.ts index f34ac042..c37ef855 100644 --- a/boilerplate/frontend/vue-prebuilt/config/passwordless.ts +++ b/boilerplate/frontend/vue-prebuilt/config/passwordless.ts @@ -1,11 +1,14 @@ import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -21,7 +24,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [Session.init()], }); diff --git a/boilerplate/frontend/vue-prebuilt/config/thirdparty.ts b/boilerplate/frontend/vue-prebuilt/config/thirdparty.ts index b708b845..d20aa8fa 100644 --- a/boilerplate/frontend/vue-prebuilt/config/thirdparty.ts +++ b/boilerplate/frontend/vue-prebuilt/config/thirdparty.ts @@ -1,11 +1,14 @@ import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -28,7 +31,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [Session.init()], }); diff --git a/boilerplate/frontend/vue-prebuilt/config/thirdpartyemailpassword.ts b/boilerplate/frontend/vue-prebuilt/config/thirdpartyemailpassword.ts index a9daf5cd..6aeab1a9 100644 --- a/boilerplate/frontend/vue-prebuilt/config/thirdpartyemailpassword.ts +++ b/boilerplate/frontend/vue-prebuilt/config/thirdpartyemailpassword.ts @@ -1,11 +1,14 @@ import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -29,7 +32,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [Session.init()], }); diff --git a/boilerplate/frontend/vue-prebuilt/config/thirdpartypasswordless.ts b/boilerplate/frontend/vue-prebuilt/config/thirdpartypasswordless.ts index 2d6d4b24..2bc6a820 100644 --- a/boilerplate/frontend/vue-prebuilt/config/thirdpartypasswordless.ts +++ b/boilerplate/frontend/vue-prebuilt/config/thirdpartypasswordless.ts @@ -1,11 +1,14 @@ import SuperTokens from "supertokens-web-js"; import Session from "supertokens-web-js/recipe/session"; +const api_port = import.meta.env.VITE_API_PORT || 3001; +const app_port = import.meta.env.VITE_APP_PORT || 3000; + export function initSuperTokensUI() { (window as any).supertokensUIInit("supertokensui", { appInfo: { - websiteDomain: "http://localhost:3000", - apiDomain: "http://localhost:3001", + websiteDomain: `http://localhost:${app_port}`, + apiDomain: `http://localhost:${api_port}`, appName: "SuperTokens Demo App", }, recipeList: [ @@ -31,7 +34,7 @@ export function initSuperTokensWebJS() { SuperTokens.init({ appInfo: { appName: "SuperTokens Demo App", - apiDomain: "http://localhost:3001", + apiDomain: `http://localhost:${api_port}`, }, recipeList: [Session.init()], }); From e0b37e55a85b1ac8ab76562baa5f55ed2aab0932 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Wed, 2 Oct 2024 12:21:11 +0530 Subject: [PATCH 06/16] express js config updated for supporting react js dynamic port --- boilerplate/backend/node-express/config/all_auth.ts | 2 +- boilerplate/backend/node-express/config/emailpassword.ts | 2 +- boilerplate/backend/node-express/config/multifactorauth.ts | 2 +- boilerplate/backend/node-express/config/multitenancy.ts | 2 +- boilerplate/backend/node-express/config/passwordless.ts | 2 +- boilerplate/backend/node-express/config/thirdparty.ts | 2 +- .../backend/node-express/config/thirdpartyemailpassword.ts | 2 +- .../backend/node-express/config/thirdpartypasswordless.ts | 2 +- boilerplate/backend/node-express/index.ts | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/boilerplate/backend/node-express/config/all_auth.ts b/boilerplate/backend/node-express/config/all_auth.ts index 188792d0..54bf9d0e 100644 --- a/boilerplate/backend/node-express/config/all_auth.ts +++ b/boilerplate/backend/node-express/config/all_auth.ts @@ -13,7 +13,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/emailpassword.ts b/boilerplate/backend/node-express/config/emailpassword.ts index b1879648..15f84dd6 100644 --- a/boilerplate/backend/node-express/config/emailpassword.ts +++ b/boilerplate/backend/node-express/config/emailpassword.ts @@ -11,7 +11,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/multifactorauth.ts b/boilerplate/backend/node-express/config/multifactorauth.ts index 7dfda943..80c5d87d 100644 --- a/boilerplate/backend/node-express/config/multifactorauth.ts +++ b/boilerplate/backend/node-express/config/multifactorauth.ts @@ -16,7 +16,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/multitenancy.ts b/boilerplate/backend/node-express/config/multitenancy.ts index dab320b9..12f857c1 100644 --- a/boilerplate/backend/node-express/config/multitenancy.ts +++ b/boilerplate/backend/node-express/config/multitenancy.ts @@ -13,7 +13,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/passwordless.ts b/boilerplate/backend/node-express/config/passwordless.ts index 8f0dc2e3..590b8799 100644 --- a/boilerplate/backend/node-express/config/passwordless.ts +++ b/boilerplate/backend/node-express/config/passwordless.ts @@ -11,7 +11,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/thirdparty.ts b/boilerplate/backend/node-express/config/thirdparty.ts index 6374ea22..51391189 100644 --- a/boilerplate/backend/node-express/config/thirdparty.ts +++ b/boilerplate/backend/node-express/config/thirdparty.ts @@ -11,7 +11,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts b/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts index b495a612..614fca80 100644 --- a/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts +++ b/boilerplate/backend/node-express/config/thirdpartyemailpassword.ts @@ -12,7 +12,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/config/thirdpartypasswordless.ts b/boilerplate/backend/node-express/config/thirdpartypasswordless.ts index 778cc138..f5a25b6f 100644 --- a/boilerplate/backend/node-express/config/thirdpartypasswordless.ts +++ b/boilerplate/backend/node-express/config/thirdpartypasswordless.ts @@ -12,7 +12,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.VITE_APP_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/backend/node-express/index.ts b/boilerplate/backend/node-express/index.ts index b0b15dec..1c5888c6 100644 --- a/boilerplate/backend/node-express/index.ts +++ b/boilerplate/backend/node-express/index.ts @@ -43,6 +43,6 @@ app.get("/tenants", async (req, res) => { // returns 401 to the client. app.use(errorHandler()); -const port = process.env.VITE_API_PORT || 3001; +const port = process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; app.listen(port, () => console.log(`API Server listening on port ${port}`)); From ab5bd9ecb0a6aff9d56cdfb9f9f4f4835b0773cf Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Wed, 2 Oct 2024 12:22:38 +0530 Subject: [PATCH 07/16] React js dynamic port configuration --- .../supertokens-react-multitenancy/config/multitenancy.tsx | 2 +- boilerplate/frontend/supertokens-react/config/all_auth.tsx | 2 +- boilerplate/frontend/supertokens-react/config/emailpassword.tsx | 2 +- .../frontend/supertokens-react/config/multifactorauth.tsx | 2 +- boilerplate/frontend/supertokens-react/config/passwordless.tsx | 2 +- boilerplate/frontend/supertokens-react/config/thirdparty.tsx | 2 +- .../supertokens-react/config/thirdpartyemailpassword.tsx | 2 +- .../supertokens-react/config/thirdpartypasswordless.tsx | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/boilerplate/frontend/supertokens-react-multitenancy/config/multitenancy.tsx b/boilerplate/frontend/supertokens-react-multitenancy/config/multitenancy.tsx index 3e832cb3..c3743b8b 100644 --- a/boilerplate/frontend/supertokens-react-multitenancy/config/multitenancy.tsx +++ b/boilerplate/frontend/supertokens-react-multitenancy/config/multitenancy.tsx @@ -14,7 +14,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/all_auth.tsx b/boilerplate/frontend/supertokens-react/config/all_auth.tsx index c06b298c..9a201f89 100644 --- a/boilerplate/frontend/supertokens-react/config/all_auth.tsx +++ b/boilerplate/frontend/supertokens-react/config/all_auth.tsx @@ -14,7 +14,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/emailpassword.tsx b/boilerplate/frontend/supertokens-react/config/emailpassword.tsx index 6ba7a8ad..e49dd210 100644 --- a/boilerplate/frontend/supertokens-react/config/emailpassword.tsx +++ b/boilerplate/frontend/supertokens-react/config/emailpassword.tsx @@ -9,7 +9,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/multifactorauth.tsx b/boilerplate/frontend/supertokens-react/config/multifactorauth.tsx index 6e1891c8..369c5286 100644 --- a/boilerplate/frontend/supertokens-react/config/multifactorauth.tsx +++ b/boilerplate/frontend/supertokens-react/config/multifactorauth.tsx @@ -19,7 +19,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/passwordless.tsx b/boilerplate/frontend/supertokens-react/config/passwordless.tsx index def20d2f..889b57e7 100644 --- a/boilerplate/frontend/supertokens-react/config/passwordless.tsx +++ b/boilerplate/frontend/supertokens-react/config/passwordless.tsx @@ -10,7 +10,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/thirdparty.tsx b/boilerplate/frontend/supertokens-react/config/thirdparty.tsx index 3dc4627b..72a1a5dc 100644 --- a/boilerplate/frontend/supertokens-react/config/thirdparty.tsx +++ b/boilerplate/frontend/supertokens-react/config/thirdparty.tsx @@ -9,7 +9,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/thirdpartyemailpassword.tsx b/boilerplate/frontend/supertokens-react/config/thirdpartyemailpassword.tsx index 2f91c29e..472a3a01 100644 --- a/boilerplate/frontend/supertokens-react/config/thirdpartyemailpassword.tsx +++ b/boilerplate/frontend/supertokens-react/config/thirdpartyemailpassword.tsx @@ -11,7 +11,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } diff --git a/boilerplate/frontend/supertokens-react/config/thirdpartypasswordless.tsx b/boilerplate/frontend/supertokens-react/config/thirdpartypasswordless.tsx index 8c9d0417..4d0581b3 100644 --- a/boilerplate/frontend/supertokens-react/config/thirdpartypasswordless.tsx +++ b/boilerplate/frontend/supertokens-react/config/thirdpartypasswordless.tsx @@ -12,7 +12,7 @@ export function getApiDomain() { } export function getWebsiteDomain() { - const websitePort = process.env.REACT_APP_WEBSITE_PORT || 3000; + const websitePort = process.env.REACT_APP_WEBSITE_PORT || process.env.PORT || 3000; const websiteUrl = process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; return websiteUrl; } From b126b9e245524c6630dc48c047bb4a5f7f7e6b59 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Fri, 4 Oct 2024 12:05:56 +0530 Subject: [PATCH 08/16] dynamic custom port nest js --- boilerplate/backend/nest/config/all_auth.ts | 20 ++++++++++++++++--- .../backend/nest/config/emailpassword.ts | 20 ++++++++++++++++--- .../backend/nest/config/multifactorauth.ts | 20 ++++++++++++++++--- .../backend/nest/config/multitenancy.ts | 20 ++++++++++++++++--- .../backend/nest/config/passwordless.ts | 20 ++++++++++++++++--- boilerplate/backend/nest/config/thirdparty.ts | 20 ++++++++++++++++--- .../nest/config/thirdpartyemailpassword.ts | 20 ++++++++++++++++--- .../nest/config/thirdpartypasswordless.ts | 20 ++++++++++++++++--- boilerplate/backend/nest/src/config.ts | 2 +- boilerplate/backend/nest/src/main.ts | 4 +++- 10 files changed, 140 insertions(+), 26 deletions(-) diff --git a/boilerplate/backend/nest/config/all_auth.ts b/boilerplate/backend/nest/config/all_auth.ts index d6717b91..3c48db05 100644 --- a/boilerplate/backend/nest/config/all_auth.ts +++ b/boilerplate/backend/nest/config/all_auth.ts @@ -5,11 +5,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/emailpassword.ts b/boilerplate/backend/nest/config/emailpassword.ts index 4e438d81..7746c121 100644 --- a/boilerplate/backend/nest/config/emailpassword.ts +++ b/boilerplate/backend/nest/config/emailpassword.ts @@ -3,11 +3,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/multifactorauth.ts b/boilerplate/backend/nest/config/multifactorauth.ts index 7e9631e5..2acb20ca 100644 --- a/boilerplate/backend/nest/config/multifactorauth.ts +++ b/boilerplate/backend/nest/config/multifactorauth.ts @@ -9,11 +9,25 @@ import AccountLinking from 'supertokens-node/recipe/accountlinking'; import EmailVerification from 'supertokens-node/recipe/emailverification'; import TOTP from 'supertokens-node/recipe/totp'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/multitenancy.ts b/boilerplate/backend/nest/config/multitenancy.ts index b84dbd29..72c298b5 100644 --- a/boilerplate/backend/nest/config/multitenancy.ts +++ b/boilerplate/backend/nest/config/multitenancy.ts @@ -5,11 +5,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/passwordless.ts b/boilerplate/backend/nest/config/passwordless.ts index ff4317e1..f8dcf5ce 100644 --- a/boilerplate/backend/nest/config/passwordless.ts +++ b/boilerplate/backend/nest/config/passwordless.ts @@ -3,11 +3,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/thirdparty.ts b/boilerplate/backend/nest/config/thirdparty.ts index eb03af0e..869c23b9 100644 --- a/boilerplate/backend/nest/config/thirdparty.ts +++ b/boilerplate/backend/nest/config/thirdparty.ts @@ -3,11 +3,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/thirdpartyemailpassword.ts b/boilerplate/backend/nest/config/thirdpartyemailpassword.ts index 3b10200c..fe3d8de3 100644 --- a/boilerplate/backend/nest/config/thirdpartyemailpassword.ts +++ b/boilerplate/backend/nest/config/thirdpartyemailpassword.ts @@ -4,11 +4,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/config/thirdpartypasswordless.ts b/boilerplate/backend/nest/config/thirdpartypasswordless.ts index 3f1ab377..d7d712c6 100644 --- a/boilerplate/backend/nest/config/thirdpartypasswordless.ts +++ b/boilerplate/backend/nest/config/thirdpartypasswordless.ts @@ -4,11 +4,25 @@ import Session from 'supertokens-node/recipe/session'; import Dashboard from 'supertokens-node/recipe/dashboard'; import UserRoles from 'supertokens-node/recipe/userroles'; +export function getApiDomain() { + const apiPort = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; + const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`; + return apiUrl; +} + +export function getWebsiteDomain() { + const websitePort = process.env.VITE_APP_PORT || process.env.PORT || 3000; + const websiteUrl = + process.env.REACT_APP_WEBSITE_URL || `http://localhost:${websitePort}`; + return websiteUrl; +} + export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', - apiDomain: 'http://localhost:3001', - websiteDomain: 'http://localhost:3000', + appName: 'Supertokens Demo App', + apiDomain: getApiDomain(), + websiteDomain: getWebsiteDomain(), apiBasePath: '/auth', websiteBasePath: '/auth', }; diff --git a/boilerplate/backend/nest/src/config.ts b/boilerplate/backend/nest/src/config.ts index 2bfccd29..90a5acb5 100644 --- a/boilerplate/backend/nest/src/config.ts +++ b/boilerplate/backend/nest/src/config.ts @@ -1,6 +1,6 @@ export const appInfo = { // Learn more about this on https://supertokens.com/docs/thirdpartypasswordless/appInfo - appName: 'ST', + appName: 'SuperTokens Test App', apiDomain: '', websiteDomain: '', apiBasePath: '', diff --git a/boilerplate/backend/nest/src/main.ts b/boilerplate/backend/nest/src/main.ts index e2a6f9cd..3d8002dd 100644 --- a/boilerplate/backend/nest/src/main.ts +++ b/boilerplate/backend/nest/src/main.ts @@ -6,12 +6,14 @@ import * as SuperTokensConfig from './config'; async function bootstrap() { const app = await NestFactory.create(AppModule); + const port = + process.env.REACT_APP_API_PORT || process.env.VITE_API_PORT || 3001; app.enableCors({ origin: [SuperTokensConfig.appInfo.websiteDomain], allowedHeaders: ['content-type', ...supertokens.getAllCORSHeaders()], credentials: true, }); app.useGlobalFilters(new SupertokensExceptionFilter()); - await app.listen(3001); + await app.listen(port); } bootstrap(); From 62698e29904bbee1123a69a0b5b3ad1b08677cc0 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Fri, 4 Oct 2024 19:10:38 +0530 Subject: [PATCH 09/16] flask dynamic port --- boilerplate/backend/python-flask/app.py | 3 ++- .../backend/python-flask/config/all_auth.py | 17 +++++++++++++++-- .../python-flask/config/emailpassword.py | 15 +++++++++++++-- .../backend/python-flask/config/multitenancy.py | 16 ++++++++++++++-- .../backend/python-flask/config/passwordless.py | 16 ++++++++++++++-- .../backend/python-flask/config/thirdparty.py | 16 ++++++++++++++-- .../config/thirdpartyemailpassword.py | 16 ++++++++++++++-- .../config/thirdpartypasswordless.py | 16 ++++++++++++++-- 8 files changed, 100 insertions(+), 15 deletions(-) diff --git a/boilerplate/backend/python-flask/app.py b/boilerplate/backend/python-flask/app.py index a606fec4..28bf477f 100644 --- a/boilerplate/backend/python-flask/app.py +++ b/boilerplate/backend/python-flask/app.py @@ -65,4 +65,5 @@ def catch_all(u_path: str): # pylint: disable=unused-argument if __name__ == "__main__": - app.run(host="0.0.0.0", port=int("3001"), debug=True) + port = int(os.environ.get('REACT_APP_API_PORT') or os.environ.get('VITE_API_PORT') or 3001) + app.run(host="0.0.0.0", port=port, debug=True) diff --git a/boilerplate/backend/python-flask/config/all_auth.py b/boilerplate/backend/python-flask/config/all_auth.py index e1002737..462a2f3c 100644 --- a/boilerplate/backend/python-flask/config/all_auth.py +++ b/boilerplate/backend/python-flask/config/all_auth.py @@ -1,3 +1,5 @@ +import os + from supertokens_python import init, InputAppInfo, SupertokensConfig from supertokens_python.recipe import emailpassword, thirdparty, passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig @@ -7,14 +9,25 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" diff --git a/boilerplate/backend/python-flask/config/emailpassword.py b/boilerplate/backend/python-flask/config/emailpassword.py index 7ea168af..807db34f 100644 --- a/boilerplate/backend/python-flask/config/emailpassword.py +++ b/boilerplate/backend/python-flask/config/emailpassword.py @@ -4,14 +4,25 @@ SupertokensConfig, ) + +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" diff --git a/boilerplate/backend/python-flask/config/multitenancy.py b/boilerplate/backend/python-flask/config/multitenancy.py index 37cd54f1..715fd4ba 100644 --- a/boilerplate/backend/python-flask/config/multitenancy.py +++ b/boilerplate/backend/python-flask/config/multitenancy.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, emailpassword, dashboard, passwordless from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" diff --git a/boilerplate/backend/python-flask/config/passwordless.py b/boilerplate/backend/python-flask/config/passwordless.py index f9502260..88addb20 100644 --- a/boilerplate/backend/python-flask/config/passwordless.py +++ b/boilerplate/backend/python-flask/config/passwordless.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" diff --git a/boilerplate/backend/python-flask/config/thirdparty.py b/boilerplate/backend/python-flask/config/thirdparty.py index eb4e2364..50e363cb 100644 --- a/boilerplate/backend/python-flask/config/thirdparty.py +++ b/boilerplate/backend/python-flask/config/thirdparty.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, dashboard from supertokens_python.recipe.thirdparty.provider import ProviderInput, ProviderConfig, ProviderClientConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" diff --git a/boilerplate/backend/python-flask/config/thirdpartyemailpassword.py b/boilerplate/backend/python-flask/config/thirdpartyemailpassword.py index c5f102d8..0a195a67 100644 --- a/boilerplate/backend/python-flask/config/thirdpartyemailpassword.py +++ b/boilerplate/backend/python-flask/config/thirdpartyemailpassword.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, emailpassword, dashboard from supertokens_python.recipe.thirdparty.provider import ProviderInput, ProviderConfig, ProviderClientConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" diff --git a/boilerplate/backend/python-flask/config/thirdpartypasswordless.py b/boilerplate/backend/python-flask/config/thirdpartypasswordless.py index 4f567aa2..3843a74d 100644 --- a/boilerplate/backend/python-flask/config/thirdpartypasswordless.py +++ b/boilerplate/backend/python-flask/config/thirdpartypasswordless.py @@ -1,3 +1,5 @@ +import os + from supertokens_python import init, InputAppInfo, SupertokensConfig from supertokens_python.recipe import thirdparty, passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig @@ -7,14 +9,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "flask" From 6fa7b554c309a467ce91315f627257b30c091d7d Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Sat, 5 Oct 2024 11:30:07 +0530 Subject: [PATCH 10/16] fastapi dynamic port --- boilerplate/backend/python-fastapi/app.py | 4 +++- .../backend/python-fastapi/config/all_auth.py | 17 +++++++++++++++-- .../python-fastapi/config/emailpassword.py | 17 +++++++++++++++-- .../python-fastapi/config/multitenancy.py | 17 +++++++++++++++-- .../python-fastapi/config/passwordless.py | 16 ++++++++++++++-- .../backend/python-fastapi/config/thirdparty.py | 17 +++++++++++++++-- .../config/thirdpartyemailpassword.py | 15 +++++++++++++-- .../config/thirdpartypasswordless.py | 17 +++++++++++++++-- 8 files changed, 105 insertions(+), 15 deletions(-) diff --git a/boilerplate/backend/python-fastapi/app.py b/boilerplate/backend/python-fastapi/app.py index aac1a49c..f18d8bd5 100644 --- a/boilerplate/backend/python-fastapi/app.py +++ b/boilerplate/backend/python-fastapi/app.py @@ -1,4 +1,5 @@ import uvicorn +import os from fastapi import FastAPI, Depends from starlette.middleware.cors import CORSMiddleware @@ -55,4 +56,5 @@ async def get_tenants(): ) if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=3001) + port = int(os.environ.get('REACT_APP_API_PORT') or os.environ.get('VITE_API_PORT') or 3001) + uvicorn.run(app, host="0.0.0.0", port=port) diff --git a/boilerplate/backend/python-fastapi/config/all_auth.py b/boilerplate/backend/python-fastapi/config/all_auth.py index 24012a6c..3c3bd48a 100644 --- a/boilerplate/backend/python-fastapi/config/all_auth.py +++ b/boilerplate/backend/python-fastapi/config/all_auth.py @@ -1,3 +1,5 @@ +import os + from supertokens_python import init, InputAppInfo, SupertokensConfig from supertokens_python.recipe import emailpassword, thirdparty, passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig @@ -7,14 +9,25 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" diff --git a/boilerplate/backend/python-fastapi/config/emailpassword.py b/boilerplate/backend/python-fastapi/config/emailpassword.py index 637f0710..fcf7b93d 100644 --- a/boilerplate/backend/python-fastapi/config/emailpassword.py +++ b/boilerplate/backend/python-fastapi/config/emailpassword.py @@ -1,17 +1,30 @@ +import os + from supertokens_python.recipe import emailpassword, session, dashboard from supertokens_python import ( InputAppInfo, SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" diff --git a/boilerplate/backend/python-fastapi/config/multitenancy.py b/boilerplate/backend/python-fastapi/config/multitenancy.py index 23b34d4c..2e8d45d1 100644 --- a/boilerplate/backend/python-fastapi/config/multitenancy.py +++ b/boilerplate/backend/python-fastapi/config/multitenancy.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, emailpassword, dashboard, passwordless from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig from supertokens_python import ( @@ -5,14 +7,25 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" diff --git a/boilerplate/backend/python-fastapi/config/passwordless.py b/boilerplate/backend/python-fastapi/config/passwordless.py index 52706ef8..533323c0 100644 --- a/boilerplate/backend/python-fastapi/config/passwordless.py +++ b/boilerplate/backend/python-fastapi/config/passwordless.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" diff --git a/boilerplate/backend/python-fastapi/config/thirdparty.py b/boilerplate/backend/python-fastapi/config/thirdparty.py index 42c94e5a..cc83f5f7 100644 --- a/boilerplate/backend/python-fastapi/config/thirdparty.py +++ b/boilerplate/backend/python-fastapi/config/thirdparty.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, dashboard from supertokens_python.recipe.thirdparty.provider import ProviderInput, ProviderConfig, ProviderClientConfig from supertokens_python import ( @@ -5,14 +7,25 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" diff --git a/boilerplate/backend/python-fastapi/config/thirdpartyemailpassword.py b/boilerplate/backend/python-fastapi/config/thirdpartyemailpassword.py index 50fa2af6..50cdbab4 100644 --- a/boilerplate/backend/python-fastapi/config/thirdpartyemailpassword.py +++ b/boilerplate/backend/python-fastapi/config/thirdpartyemailpassword.py @@ -1,3 +1,4 @@ +import os from supertokens_python.recipe import session, thirdparty, emailpassword, dashboard from supertokens_python.recipe.thirdparty.provider import ProviderInput, ProviderConfig, ProviderClientConfig from supertokens_python import ( @@ -5,14 +6,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" diff --git a/boilerplate/backend/python-fastapi/config/thirdpartypasswordless.py b/boilerplate/backend/python-fastapi/config/thirdpartypasswordless.py index b6fd5c3d..935715c1 100644 --- a/boilerplate/backend/python-fastapi/config/thirdpartypasswordless.py +++ b/boilerplate/backend/python-fastapi/config/thirdpartypasswordless.py @@ -1,3 +1,5 @@ +import os + from supertokens_python import init, InputAppInfo, SupertokensConfig from supertokens_python.recipe import thirdparty, passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig @@ -7,14 +9,25 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) framework = "fastapi" From 319f80f49734cc8c67bf61e81432a15542b9832c Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Sat, 5 Oct 2024 16:23:55 +0530 Subject: [PATCH 11/16] Django custom port --- .../backend/python-drf/app/config/all_auth.py | 18 ++++++++++++++++-- .../python-drf/app/config/emailpassword.py | 15 +++++++++++++-- .../python-drf/app/config/multitenancy.py | 16 ++++++++++++++-- .../python-drf/app/config/passwordless.py | 16 ++++++++++++++-- .../python-drf/app/config/thirdparty.py | 16 ++++++++++++++-- .../app/config/thirdpartyemailpassword.py | 16 ++++++++++++++-- .../app/config/thirdpartypasswordless.py | 16 ++++++++++++++-- boilerplate/backend/python-drf/app/settings.py | 5 +++-- boilerplate/backend/python-drf/manage.py | 4 +++- 9 files changed, 105 insertions(+), 17 deletions(-) diff --git a/boilerplate/backend/python-drf/app/config/all_auth.py b/boilerplate/backend/python-drf/app/config/all_auth.py index 1364672f..44e43d10 100644 --- a/boilerplate/backend/python-drf/app/config/all_auth.py +++ b/boilerplate/backend/python-drf/app/config/all_auth.py @@ -1,3 +1,5 @@ +import os + from supertokens_python import init, InputAppInfo, SupertokensConfig from supertokens_python.recipe import emailpassword, thirdparty, passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig @@ -7,14 +9,26 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + + + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/config/emailpassword.py b/boilerplate/backend/python-drf/app/config/emailpassword.py index 92f4d28c..8b8bab0f 100644 --- a/boilerplate/backend/python-drf/app/config/emailpassword.py +++ b/boilerplate/backend/python-drf/app/config/emailpassword.py @@ -1,17 +1,28 @@ +import os + from supertokens_python.recipe import emailpassword, session, dashboard from supertokens_python import ( InputAppInfo, SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/config/multitenancy.py b/boilerplate/backend/python-drf/app/config/multitenancy.py index d5321186..b8354f81 100644 --- a/boilerplate/backend/python-drf/app/config/multitenancy.py +++ b/boilerplate/backend/python-drf/app/config/multitenancy.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, emailpassword, dashboard, passwordless from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/config/passwordless.py b/boilerplate/backend/python-drf/app/config/passwordless.py index d5b87f8e..8578e14a 100644 --- a/boilerplate/backend/python-drf/app/config/passwordless.py +++ b/boilerplate/backend/python-drf/app/config/passwordless.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/config/thirdparty.py b/boilerplate/backend/python-drf/app/config/thirdparty.py index 3a9bf231..511a85ff 100644 --- a/boilerplate/backend/python-drf/app/config/thirdparty.py +++ b/boilerplate/backend/python-drf/app/config/thirdparty.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, dashboard from supertokens_python.recipe.thirdparty.provider import ProviderInput, ProviderConfig, ProviderClientConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/config/thirdpartyemailpassword.py b/boilerplate/backend/python-drf/app/config/thirdpartyemailpassword.py index 3c06bd01..4519635d 100644 --- a/boilerplate/backend/python-drf/app/config/thirdpartyemailpassword.py +++ b/boilerplate/backend/python-drf/app/config/thirdpartyemailpassword.py @@ -1,3 +1,5 @@ +import os + from supertokens_python.recipe import session, thirdparty, emailpassword, dashboard from supertokens_python.recipe.thirdparty.provider import ProviderInput, ProviderConfig, ProviderClientConfig from supertokens_python import ( @@ -5,14 +7,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/config/thirdpartypasswordless.py b/boilerplate/backend/python-drf/app/config/thirdpartypasswordless.py index dd11ce7c..35993736 100644 --- a/boilerplate/backend/python-drf/app/config/thirdpartypasswordless.py +++ b/boilerplate/backend/python-drf/app/config/thirdpartypasswordless.py @@ -1,3 +1,5 @@ +import os + from supertokens_python import init, InputAppInfo, SupertokensConfig from supertokens_python.recipe import thirdparty, passwordless, session, dashboard from supertokens_python.recipe.passwordless import ContactEmailOrPhoneConfig @@ -7,14 +9,24 @@ SupertokensConfig, ) +def get_api_domain(): + api_port = os.getenv("REACT_APP_API_PORT") or os.getenv("VITE_API_PORT") or "3001" + api_url = os.getenv("REACT_APP_API_URL") or f"http://localhost:{api_port}" + return api_url + +def get_website_domain(): + website_port = os.getenv("REACT_APP_WEBSITE_PORT") or os.getenv("VITE_APP_PORT") or os.getenv("PORT") or "3000" + website_url = os.getenv("REACT_APP_WEBSITE_URL") or f"http://localhost:{website_port}" + return website_url + # this is the location of the SuperTokens core. supertokens_config = SupertokensConfig( connection_uri="https://try.supertokens.com") app_info = InputAppInfo( app_name="Supertokens", - api_domain="http://localhost:3001", - website_domain="http://localhost:3000", + api_domain=get_api_domain(), + website_domain=get_website_domain(), ) # recipeList contains all the modules that you want to diff --git a/boilerplate/backend/python-drf/app/settings.py b/boilerplate/backend/python-drf/app/settings.py index 8629cfe0..f4cbda78 100644 --- a/boilerplate/backend/python-drf/app/settings.py +++ b/boilerplate/backend/python-drf/app/settings.py @@ -9,6 +9,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ +import os from corsheaders.defaults import default_headers from typing import List @@ -145,13 +146,13 @@ CORS_ORIGIN_WHITELIST = [ - "http://localhost:3000" + f"http://localhost:{os.environ.get('VITE_APP_PORT', os.environ.get('PORT', 3000))}", ] CORS_ALLOW_CREDENTIALS = True CORS_ALLOWED_ORIGINS = [ - "http://localhost:3000" + f"http://localhost:{os.environ.get('VITE_APP_PORT', os.environ.get('PORT', 3000))}", ] CORS_ALLOW_HEADERS: List[str] = list(default_headers) + [ diff --git a/boilerplate/backend/python-drf/manage.py b/boilerplate/backend/python-drf/manage.py index 73e2ddcf..8c7579ad 100755 --- a/boilerplate/backend/python-drf/manage.py +++ b/boilerplate/backend/python-drf/manage.py @@ -3,7 +3,9 @@ import os import sys from django.core.management.commands.runserver import Command as runserver -runserver.default_port = "3001" + +port = int(os.environ.get('REACT_APP_API_PORT') or os.environ.get('VITE_API_PORT') or 3001) +runserver.default_port = port def main(): From 7b3200a70bc964fe75693ce2bc8ca729fbc2490c Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Sat, 5 Oct 2024 18:28:50 +0530 Subject: [PATCH 12/16] go custom port added --- .../backend/go-http/config/all_auth.go | 41 ++++++++++++++++-- .../backend/go-http/config/emailpassword.go | 38 ++++++++++++++++- .../backend/go-http/config/multitenancy.go | 42 +++++++++++++++++-- .../backend/go-http/config/passwordless.go | 38 ++++++++++++++++- .../backend/go-http/config/thirdparty.go | 38 ++++++++++++++++- .../go-http/config/thirdpartyemailpassword.go | 40 ++++++++++++++++-- .../go-http/config/thirdpartypasswordless.go | 42 +++++++++++++++++-- boilerplate/backend/go-http/main.go | 38 ++++++++++++++--- 8 files changed, 292 insertions(+), 25 deletions(-) diff --git a/boilerplate/backend/go-http/config/all_auth.go b/boilerplate/backend/go-http/config/all_auth.go index e8f47672..3addfd6c 100644 --- a/boilerplate/backend/go-http/config/all_auth.go +++ b/boilerplate/backend/go-http/config/all_auth.go @@ -1,7 +1,9 @@ package main import ( - "github.com/supertokens/supertokens-golang/recipe/dashboard" + "os" + + "github.com/supertokens/supertokens-golang/recipe/dashboard" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/thirdparty" @@ -11,14 +13,47 @@ import ( "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ emailpassword.Init(nil), diff --git a/boilerplate/backend/go-http/config/emailpassword.go b/boilerplate/backend/go-http/config/emailpassword.go index e415559a..c8983e50 100644 --- a/boilerplate/backend/go-http/config/emailpassword.go +++ b/boilerplate/backend/go-http/config/emailpassword.go @@ -1,20 +1,54 @@ package main import ( + "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ emailpassword.Init(nil), diff --git a/boilerplate/backend/go-http/config/multitenancy.go b/boilerplate/backend/go-http/config/multitenancy.go index 5dac724c..1e79ba60 100644 --- a/boilerplate/backend/go-http/config/multitenancy.go +++ b/boilerplate/backend/go-http/config/multitenancy.go @@ -1,23 +1,57 @@ package main import ( + "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" - "github.com/supertokens/supertokens-golang/recipe/session" - "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/passwordless" "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" + "github.com/supertokens/supertokens-golang/recipe/session" + "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ thirdparty.Init(nil), diff --git a/boilerplate/backend/go-http/config/passwordless.go b/boilerplate/backend/go-http/config/passwordless.go index f245f35f..1d59cbc1 100644 --- a/boilerplate/backend/go-http/config/passwordless.go +++ b/boilerplate/backend/go-http/config/passwordless.go @@ -1,6 +1,8 @@ package main import ( + "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" "github.com/supertokens/supertokens-golang/recipe/passwordless" "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" @@ -8,14 +10,46 @@ import ( "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ passwordless.Init(plessmodels.TypeInput{ diff --git a/boilerplate/backend/go-http/config/thirdparty.go b/boilerplate/backend/go-http/config/thirdparty.go index b9a132cf..cb0780ef 100644 --- a/boilerplate/backend/go-http/config/thirdparty.go +++ b/boilerplate/backend/go-http/config/thirdparty.go @@ -1,6 +1,8 @@ package main import ( + "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/thirdparty" @@ -8,14 +10,46 @@ import ( "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ thirdparty.Init(&tpmodels.TypeInput{ diff --git a/boilerplate/backend/go-http/config/thirdpartyemailpassword.go b/boilerplate/backend/go-http/config/thirdpartyemailpassword.go index d7988586..ed182035 100644 --- a/boilerplate/backend/go-http/config/thirdpartyemailpassword.go +++ b/boilerplate/backend/go-http/config/thirdpartyemailpassword.go @@ -1,22 +1,56 @@ package main import ( + "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" - "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/emailpassword" + "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ emailpassword.Init(nil), diff --git a/boilerplate/backend/go-http/config/thirdpartypasswordless.go b/boilerplate/backend/go-http/config/thirdpartypasswordless.go index 20b7c005..96342c2f 100644 --- a/boilerplate/backend/go-http/config/thirdpartypasswordless.go +++ b/boilerplate/backend/go-http/config/thirdpartypasswordless.go @@ -1,23 +1,57 @@ package main import ( + "os" + "github.com/supertokens/supertokens-golang/recipe/dashboard" + "github.com/supertokens/supertokens-golang/recipe/passwordless" + "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" "github.com/supertokens/supertokens-golang/recipe/session" "github.com/supertokens/supertokens-golang/recipe/thirdparty" "github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels" - "github.com/supertokens/supertokens-golang/recipe/passwordless" - "github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels" "github.com/supertokens/supertokens-golang/supertokens" ) +func getApiDomain() string { + apiPortStr := os.Getenv("REACT_APP_API_PORT") + if apiPortStr == "" { + apiPortStr = os.Getenv("VITE_API_PORT") + if apiPortStr == "" { + apiPortStr = "3001" + } + } + apiUrl := os.Getenv("REACT_APP_API_URL") + if apiUrl == "" { + apiUrl = "http://localhost:" + apiPortStr + } + + return apiUrl +} + +func getWebsiteDomain() string { + websitePortStr := os.Getenv("PORT") + if websitePortStr == "" { + websitePortStr = os.Getenv("VITE_APP_PORT") + if websitePortStr == "" { + websitePortStr = "3000" + } + } + websiteUrl := os.Getenv("REACT_APP_WEBSITE_URL") + if websiteUrl == "" { + websiteUrl = "http://localhost:" + websitePortStr + } + + return websiteUrl +} + var SuperTokensConfig = supertokens.TypeInput{ Supertokens: &supertokens.ConnectionInfo{ ConnectionURI: "https://try.supertokens.com", }, AppInfo: supertokens.AppInfo{ AppName: "SuperTokens Demo App", - APIDomain: "http://localhost:3001", - WebsiteDomain: "http://localhost:3000", + APIDomain: getApiDomain(), + WebsiteDomain: getWebsiteDomain(), }, RecipeList: []supertokens.Recipe{ passwordless.Init(plessmodels.TypeInput{ diff --git a/boilerplate/backend/go-http/main.go b/boilerplate/backend/go-http/main.go index 818caed5..f605b94a 100644 --- a/boilerplate/backend/go-http/main.go +++ b/boilerplate/backend/go-http/main.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "strings" + "os" "github.com/supertokens/supertokens-golang/recipe/multitenancy" "github.com/supertokens/supertokens-golang/recipe/session" @@ -16,8 +17,15 @@ func main() { if err != nil { panic(err.Error()) } - - http.ListenAndServe(":3001", corsMiddleware( + port := os.Getenv("VITE_API_PORT") + if port == "" { + port = os.Getenv("REACT_APP_API_PORT") + } + if port == "" { + port = "3001" + } + + http.ListenAndServe(":"+port, corsMiddleware( supertokens.Middleware(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { // Handle your APIs.. @@ -37,8 +45,19 @@ func main() { func corsMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(response http.ResponseWriter, r *http.Request) { - response.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000") - response.Header().Set("Access-Control-Allow-Credentials", "true") + allowedOrigins := []string{ + "http://localhost:" + os.Getenv("VITE_APP_PORT"), + "http://localhost:" + os.Getenv("PORT"), + "http://localhost:3000", // Default origin + } + origin := r.Header.Get("Origin") + if origin != "" && contains(allowedOrigins, origin) { + response.Header().Set("Access-Control-Allow-Origin", origin) + response.Header().Set("Access-Control-Allow-Credentials", "true") + } else { + response.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000") // Default origin + } + if r.Method == "OPTIONS" { response.Header().Set("Access-Control-Allow-Headers", strings.Join(append([]string{"Content-Type"}, supertokens.GetAllCORSHeaders()...), ",")) response.Header().Set("Access-Control-Allow-Methods", "*") @@ -46,7 +65,16 @@ func corsMiddleware(next http.Handler) http.Handler { } else { next.ServeHTTP(response, r) } - }) + }) +} + +func contains(slice []string, item string) bool { + for _, s := range slice { + if s == item { + return true + } + } + return false } func sessioninfo(w http.ResponseWriter, r *http.Request) { From 2096624f8b1431188c6df02f872469c05a53869c Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Mon, 7 Oct 2024 11:05:39 +0530 Subject: [PATCH 13/16] Next js custom port --- .../app/components/callApiButton.tsx | 3 ++- .../fullstack/next-app-dir-multitenancy/app/config/appInfo.ts | 4 ++-- .../fullstack/next-app-dir/app/components/callApiButton.tsx | 3 ++- boilerplate/fullstack/next-app-dir/app/config/appInfo.ts | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/boilerplate/fullstack/next-app-dir-multitenancy/app/components/callApiButton.tsx b/boilerplate/fullstack/next-app-dir-multitenancy/app/components/callApiButton.tsx index cd3aa30b..c7a8f036 100644 --- a/boilerplate/fullstack/next-app-dir-multitenancy/app/components/callApiButton.tsx +++ b/boilerplate/fullstack/next-app-dir-multitenancy/app/components/callApiButton.tsx @@ -4,7 +4,8 @@ import styles from "../page.module.css"; export const CallAPIButton = () => { const fetchUserData = async () => { - const userInfoResponse = await fetch("http://localhost:3000/api/user"); + const port = process.env.NEXT_PUBLIC_PORT || 3000; + const userInfoResponse = await fetch(`http://localhost:${port}/api/user`); alert(JSON.stringify(await userInfoResponse.json())); }; diff --git a/boilerplate/fullstack/next-app-dir-multitenancy/app/config/appInfo.ts b/boilerplate/fullstack/next-app-dir-multitenancy/app/config/appInfo.ts index 9c3ac073..2995f416 100644 --- a/boilerplate/fullstack/next-app-dir-multitenancy/app/config/appInfo.ts +++ b/boilerplate/fullstack/next-app-dir-multitenancy/app/config/appInfo.ts @@ -1,7 +1,7 @@ export const appInfo = { appName: "SuperTokens Next.js demo app", - apiDomain: "http://localhost:3000", - websiteDomain: "http://localhost:3000", + apiDomain: `http://localhost:${process.env.NEXT_PUBLIC_PORT || 3000}`, + websiteDomain: `http://localhost:${process.env.NEXT_PUBLIC_PORT || 3000}`, apiBasePath: "/api/auth", websiteBasePath: "/auth", }; diff --git a/boilerplate/fullstack/next-app-dir/app/components/callApiButton.tsx b/boilerplate/fullstack/next-app-dir/app/components/callApiButton.tsx index cd3aa30b..c7a8f036 100644 --- a/boilerplate/fullstack/next-app-dir/app/components/callApiButton.tsx +++ b/boilerplate/fullstack/next-app-dir/app/components/callApiButton.tsx @@ -4,7 +4,8 @@ import styles from "../page.module.css"; export const CallAPIButton = () => { const fetchUserData = async () => { - const userInfoResponse = await fetch("http://localhost:3000/api/user"); + const port = process.env.NEXT_PUBLIC_PORT || 3000; + const userInfoResponse = await fetch(`http://localhost:${port}/api/user`); alert(JSON.stringify(await userInfoResponse.json())); }; diff --git a/boilerplate/fullstack/next-app-dir/app/config/appInfo.ts b/boilerplate/fullstack/next-app-dir/app/config/appInfo.ts index 9c3ac073..2995f416 100644 --- a/boilerplate/fullstack/next-app-dir/app/config/appInfo.ts +++ b/boilerplate/fullstack/next-app-dir/app/config/appInfo.ts @@ -1,7 +1,7 @@ export const appInfo = { appName: "SuperTokens Next.js demo app", - apiDomain: "http://localhost:3000", - websiteDomain: "http://localhost:3000", + apiDomain: `http://localhost:${process.env.NEXT_PUBLIC_PORT || 3000}`, + websiteDomain: `http://localhost:${process.env.NEXT_PUBLIC_PORT || 3000}`, apiBasePath: "/api/auth", websiteBasePath: "/auth", }; From 1d0d490d09342dbc8e84c667f700c5481ea6835f Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Mon, 7 Oct 2024 11:58:22 +0530 Subject: [PATCH 14/16] astro custom port added --- boilerplate/fullstack/astro/astro.config.mjs | 3 +++ boilerplate/fullstack/astro/src/components/Home.tsx | 3 ++- boilerplate/fullstack/astro/src/config/appInfo.ts | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/boilerplate/fullstack/astro/astro.config.mjs b/boilerplate/fullstack/astro/astro.config.mjs index d2c8cc4e..4bf75f38 100644 --- a/boilerplate/fullstack/astro/astro.config.mjs +++ b/boilerplate/fullstack/astro/astro.config.mjs @@ -9,5 +9,8 @@ export default defineConfig({ adapter: node({ mode: "standalone", }), + server: { + port: parseInt(process.env.PUBLIC_PORT || "5167"), + }, integrations: [react()], }); diff --git a/boilerplate/fullstack/astro/src/components/Home.tsx b/boilerplate/fullstack/astro/src/components/Home.tsx index 119b383c..7a4dc236 100644 --- a/boilerplate/fullstack/astro/src/components/Home.tsx +++ b/boilerplate/fullstack/astro/src/components/Home.tsx @@ -44,7 +44,8 @@ export default function Home({ } const fetchUserData = async () => { - const userInfoResponse = await fetch("http://localhost:4321/sessioninfo"); + const port = import.meta.env.PUBLIC_PORT || 5167; + const userInfoResponse = await fetch(`http://localhost:${port}/sessioninfo`); alert(JSON.stringify(await userInfoResponse.json())); }; diff --git a/boilerplate/fullstack/astro/src/config/appInfo.ts b/boilerplate/fullstack/astro/src/config/appInfo.ts index d4d7e19c..7eed1eb3 100644 --- a/boilerplate/fullstack/astro/src/config/appInfo.ts +++ b/boilerplate/fullstack/astro/src/config/appInfo.ts @@ -1,8 +1,13 @@ +export const getDomain = () => { + const port = import.meta.env.PUBLIC_PORT || 5167; + return `http://localhost:${port}`; +}; + export const appInfo = { // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo appName: "SuperTokens Astro demo app", - apiDomain: "http://localhost:4321", - websiteDomain: "http://localhost:4321", + apiDomain: getDomain(), + websiteDomain: getDomain(), apiBasePath: "/api/auth", websiteBasePath: "/auth", }; From af8da0b63608a2b2356ada87ba86354f7ba3aae7 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Mon, 7 Oct 2024 14:39:48 +0530 Subject: [PATCH 15/16] sveltekit custom port add --- boilerplate/fullstack/sveltekit/src/config/appInfo.ts | 6 ++++-- boilerplate/fullstack/sveltekit/vite.config.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/boilerplate/fullstack/sveltekit/src/config/appInfo.ts b/boilerplate/fullstack/sveltekit/src/config/appInfo.ts index 5a0d2b66..525cbbbd 100644 --- a/boilerplate/fullstack/sveltekit/src/config/appInfo.ts +++ b/boilerplate/fullstack/sveltekit/src/config/appInfo.ts @@ -1,8 +1,10 @@ +const port = import.meta.env.VITE_PORT || 3000; + export const appInfo = { // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo appName: "SuperTokens SvelteKit demo app", - apiDomain: "http://localhost:3000", - websiteDomain: "http://localhost:3000", + apiDomain: `http://localhost:${port}`, + websiteDomain: `http://localhost:${port}`, apiBasePath: "/api/auth", websiteBasePath: "/auth", }; diff --git a/boilerplate/fullstack/sveltekit/vite.config.ts b/boilerplate/fullstack/sveltekit/vite.config.ts index 035eae02..fc46dd11 100644 --- a/boilerplate/fullstack/sveltekit/vite.config.ts +++ b/boilerplate/fullstack/sveltekit/vite.config.ts @@ -4,6 +4,6 @@ import { defineConfig } from "vite"; export default defineConfig({ plugins: [sveltekit()], server: { - port: 3000, + port: parseInt(process.env.VITE_PORT || "3000"), }, }); From 8ebce6b9e418d284d99f855d86da0e583da585f2 Mon Sep 17 00:00:00 2001 From: Bijit-Mondal Date: Mon, 7 Oct 2024 15:02:51 +0530 Subject: [PATCH 16/16] remix custom port add --- boilerplate/fullstack/remix/app/config/appInfo.tsx | 6 ++++-- boilerplate/fullstack/remix/app/routes/_index.tsx | 3 ++- boilerplate/fullstack/remix/vite.config.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/boilerplate/fullstack/remix/app/config/appInfo.tsx b/boilerplate/fullstack/remix/app/config/appInfo.tsx index 8f2a2479..8b9291e1 100644 --- a/boilerplate/fullstack/remix/app/config/appInfo.tsx +++ b/boilerplate/fullstack/remix/app/config/appInfo.tsx @@ -1,8 +1,10 @@ +const port = import.meta.env.VITE_PORT || 3000; + export const appInfo = { // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo appName: "SuperTokens Remix demo app", - apiDomain: "http://localhost:3000", - websiteDomain: "http://localhost:3000", + apiDomain: `http://localhost:${port}`, + websiteDomain: `http://localhost:${port}`, apiBasePath: "/supertokens", websiteBasePath: "/auth", }; diff --git a/boilerplate/fullstack/remix/app/routes/_index.tsx b/boilerplate/fullstack/remix/app/routes/_index.tsx index 8f5c3e74..56ec97b5 100644 --- a/boilerplate/fullstack/remix/app/routes/_index.tsx +++ b/boilerplate/fullstack/remix/app/routes/_index.tsx @@ -54,7 +54,8 @@ export default function Home() { } const fetchUserData = async () => { - const userInfoResponse = await fetch("http://localhost:3000/sessioninfo"); + const port = import.meta.env.VITE_PORT || 3000; + const userInfoResponse = await fetch(`http://localhost:${port}/sessioninfo`); alert(JSON.stringify(await userInfoResponse.json())); }; diff --git a/boilerplate/fullstack/remix/vite.config.ts b/boilerplate/fullstack/remix/vite.config.ts index 39d8fc7f..54bee056 100644 --- a/boilerplate/fullstack/remix/vite.config.ts +++ b/boilerplate/fullstack/remix/vite.config.ts @@ -7,7 +7,7 @@ installGlobals(); export default defineConfig({ server: { - port: 3000, + port: parseInt(process.env.VITE_PORT || "3000"), }, plugins: [ remix({