From 846e671f95c5d950c59cc2ced69bf13e4bb3d9eb Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 21 Jun 2024 20:09:04 +0200 Subject: [PATCH 1/2] feat: static folder never requires an auth header --- src/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2c9cc22..7865790 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,13 @@ const createServer = (userConfig?: UserConfig) => { // Enable CORS for all requests. app.use(cors({ origin: true, credentials: true })) + // Serve a static folder, if configured. + // Because it is defined before the auth middleware, the static folder is served without authentication, + // because it is not convenient to add an auth header to a web page in the browser. + if (config.staticFolder) { + app.use(express.static(config.staticFolder)) + } + // If enabled, add auth middleware to all requests, and disable the tokens resource. if (isAuthEnabled()) { app.use(createAuthMiddleware(queries)) @@ -47,11 +54,6 @@ const createServer = (userConfig?: UserConfig) => { app.use(delayMiddleware) } - // Serve a static folder, if configured. - if (config.staticFolder) { - app.use(express.static(config.staticFolder)) - } - // On the root URL (with apiPrefix, if applicable) only a GET is allowed. const rootRouter = express.Router() const rootPath = config.apiPrefix ? `${config.apiPrefix}` : '/' From 7639a8cb51972c50d253434367ce05e2429de55d Mon Sep 17 00:00:00 2001 From: Bouwe Date: Fri, 21 Jun 2024 20:09:54 +0200 Subject: [PATCH 2/2] 0.30.2 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e38823d..a8e3154 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "temba", - "version": "0.30.1", + "version": "0.30.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "temba", - "version": "0.30.1", + "version": "0.30.2", "license": "ISC", "dependencies": { "@rakered/mongo": "^1.6.0", diff --git a/package.json b/package.json index 0e804da..0628741 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "temba", - "version": "0.30.1", + "version": "0.30.2", "description": "Get a simple REST API with zero coding in less than 30 seconds (seriously).", "type": "module", "main": "dist/src/index.js",