diff --git a/src/ServerlessOffline.js b/src/ServerlessOffline.js index bdb50c1dd..6aad6cf14 100644 --- a/src/ServerlessOffline.js +++ b/src/ServerlessOffline.js @@ -265,19 +265,6 @@ export default class ServerlessOffline { _getEvents() { const { service } = this.#serverless - // for simple API Key authentication model - if (service.provider.apiKeys) { - serverlessLog(`Key with token: ${this.#options.apiKey}`) - - if (this.#options.noAuth) { - serverlessLog( - 'Authorizers are turned off. You do not need to use x-api-key header.', - ) - } else { - serverlessLog('Remember to use x-api-key on the request headers') - } - } - const httpEvents = [] const lambdas = [] const scheduleEvents = [] @@ -285,6 +272,8 @@ export default class ServerlessOffline { const functionKeys = service.getAllFunctions() + let hasPrivateHttpEvent = false + functionKeys.forEach((functionKey) => { const functionDefinition = service.getFunction(functionKey) @@ -310,6 +299,10 @@ export default class ServerlessOffline { httpEvent.http = { ...httpApi, isHttpApi: true } } + if (http && http.private) { + hasPrivateHttpEvent = true + } + httpEvents.push(httpEvent) } @@ -329,6 +322,19 @@ export default class ServerlessOffline { }) }) + // for simple API Key authentication model + if (hasPrivateHttpEvent) { + serverlessLog(`Key with token: ${this.#options.apiKey}`) + + if (this.#options.noAuth) { + serverlessLog( + 'Authorizers are turned off. You do not need to use x-api-key header.', + ) + } else { + serverlessLog('Remember to use x-api-key on the request headers') + } + } + return { httpEvents, lambdas,