From 5a523049440cd6565cde29adc0c2cf135473ec68 Mon Sep 17 00:00:00 2001 From: David Barroso Date: Mon, 6 Nov 2023 15:47:49 +0100 Subject: [PATCH] feat: allow configuring api prefix --- docs/environment-variables.md | 1 + src/app.ts | 4 +++- src/utils/env.ts | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 2f777de15..3d32c2b76 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -8,6 +8,7 @@ | HASURA_GRAPHQL_ADMIN_SECRET\* | Hasura GraphQL Admin Secret. Required to manipulate account data. | | | AUTH_HOST | Server host. This option is available until Hasura-auth `v0.6.0`. [Docs](http://expressjs.com/en/5x/api.html#app.listen) | `0.0.0.0` | | AUTH_PORT | Server port. [Docs](http://expressjs.com/en/5x/api.html#app.listen) | `4000` | +| AUTH_API_PREFIX | API prefix | `/` | | AUTH_SERVER_URL | Server URL of where Hasura Backend Plus is running. This value is to used as a callback in email templates and for the OAuth authentication process. | | | AUTH_CLIENT_URL | URL of your frontend application. Used to redirect users to the right page once actions based on emails or OAuth succeed. | | | AUTH_CONCEAL_ERRORS | Conceal sensitive error messages to avoid leaking information about user accounts to attackers | `false` | diff --git a/src/app.ts b/src/app.ts index dce19615f..9dd2ffdff 100644 --- a/src/app.ts +++ b/src/app.ts @@ -7,6 +7,8 @@ import { httpLogger, logger, uncaughtErrorLogger } from './logger'; import { authMiddleware } from './middleware/auth'; import { addOpenApiRoute } from './openapi'; import router from './routes'; +import { ENV } from './utils/env'; + const app = express(); @@ -19,7 +21,7 @@ addOpenApiRoute(app); app.use(httpLogger); app.use(helmet(), json(), cors()); app.use(authMiddleware); -app.use(router); +app.use(ENV.AUTH_API_PREFIX, router); app.use(uncaughtErrorLogger, serverErrors); process.on('unhandledRejection', (reason) => { diff --git a/src/utils/env.ts b/src/utils/env.ts index b3650677a..c62ff2387 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -34,6 +34,9 @@ export const ENV = { get AUTH_SERVER_URL() { return castStringEnv('AUTH_SERVER_URL'); }, + get AUTH_API_PREFIX() { + return castStringEnv('AUTH_API_PREFIX', '/'); + }, // SMTP get AUTH_SMTP_PASS() {