Skip to content

Commit

Permalink
fix(lambda): resolves static index pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Oct 1, 2023
1 parent 6a4567f commit b44f434
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class LambdaServerFactory @Inject constructor(
path = path.removePrefix(routePath.removeSuffix("*"))
}
}
if (path.endsWith('/')) {
if (path.endsWith('/') || path.isEmpty()) {
path += indexFile
}
logger.debug("Serving static resource: $path")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ class HandlerTest : AbstractHandlerTest() {
assertThat(responseEvent.body, containsString(".example"))
}

@ParameterizedTest
@Event(value = "simple/requests_v1/request_static_index.json", type = APIGatewayProxyRequestEvent::class)
fun `should load static index file`(event: APIGatewayProxyRequestEvent) {
val responseEvent = handler!!.handleRequest(event, context!!)

assertNotNull(responseEvent, "Response event should be returned")
assertEquals(200, responseEvent.statusCode)
assertThat(responseEvent.body, containsString("<!doctype html>"))
}

@ParameterizedTest
@Event(value = "simple/requests_v1/request_status.json", type = APIGatewayProxyRequestEvent::class)
fun `should fetch version from status endpoint`(event: APIGatewayProxyRequestEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ class HandlerV2Test : AbstractHandlerTest() {
assertThat(responseEvent.body, containsString(".example"))
}

@ParameterizedTest
@Event(value = "simple/requests_v2/request_static_index.json", type = APIGatewayV2HTTPEvent::class)
fun `should load static index file`(event: APIGatewayV2HTTPEvent) {
val responseEvent = handler!!.handleRequest(event, context!!)

assertNotNull(responseEvent, "Response event should be returned")
assertEquals(200, responseEvent.statusCode)
assertThat(responseEvent.body, containsString("<!doctype html>"))
}

@ParameterizedTest
@Event(value = "simple/requests_v2/request_status.json", type = APIGatewayV2HTTPEvent::class)
fun `should fetch version from status endpoint`(event: APIGatewayV2HTTPEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ resources:
- path: /assets/*
response:
dir: assets

- path: /www/*
response:
dir: www
52 changes: 52 additions & 0 deletions adapter/awslambda/src/test/resources/simple/config/www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!--
~ Copyright (c) 2023.
~
~ This file is part of Imposter.
~
~ "Commons Clause" License Condition v1.0
~
~ The Software is provided to you by the Licensor under the License, as
~ defined below, subject to the following condition.
~
~ Without limiting other conditions in the License, the grant of rights
~ under the License will not include, and the License does not grant to
~ you, the right to Sell the Software.
~
~ For purposes of the foregoing, "Sell" means practicing any or all of
~ the rights granted to you under the License to provide to third parties,
~ for a fee or other consideration (including without limitation fees for
~ hosting or consulting/support services related to the Software), a
~ product or service whose value derives, entirely or substantially, from
~ the functionality of the Software. Any license notice or attribution
~ required by the License must also include this Commons Clause License
~ Condition notice.
~
~ Software: Imposter
~
~ License: GNU Lesser General Public License version 3
~
~ Licensor: Peter Cornish
~
~ Imposter is free software: you can redistribute it and/or modify
~ it under the terms of the GNU Lesser General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ Imposter is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public License
~ along with Imposter. If not, see <https://www.gnu.org/licenses/>.
-->

<!doctype html>
<html lang="en">
<head>
<title>Example</title>
</head>
<body>
Hello world
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"path": "/www/",
"httpMethod": "GET",
"headers": {},
"queryStringParameters": {},
"pathParameters": {},
"body": null,
"isBase64Encoded": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"headers": {},
"queryStringParameters": {},
"pathParameters": {},
"body": null,
"isBase64Encoded": false,
"requestContext": {
"http": {
"path": "/www/",
"method": "GET"
}
}
}

0 comments on commit b44f434

Please sign in to comment.