From 0a71e8bcb9bd5b91d1f4f13966f0f9516f3537bd Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Tue, 5 Nov 2019 15:32:06 +0200 Subject: [PATCH] check for http event with private: true fixes #832 --- src/ServerlessOffline.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ServerlessOffline.js b/src/ServerlessOffline.js index d47f968f2..9881b49c9 100644 --- a/src/ServerlessOffline.js +++ b/src/ServerlessOffline.js @@ -357,7 +357,7 @@ module.exports = class ServerlessOffline { _setupEvents() { let serviceRuntime = this.service.provider.runtime; const defaultContentType = 'application/json'; - const { apiKeys } = this.service.provider; + const { functions } = this.service.provider; const protectedRoutes = []; if (!serviceRuntime) { @@ -396,8 +396,15 @@ module.exports = class ServerlessOffline { return; } + const hasPrivateHttpEvent = Object.values(functions || []) + .some(func => (func.events || []) + .filter(e => e.http) + .map(e => e.http) + .some(e => e.private) + ); + // for simple API Key authentication model - if (apiKeys) { + if (hasPrivateHttpEvent) { this.serverlessLog(`Key with token: ${this.options.apiKey}`); if (this.options.noAuth) {