This PR contains the work done to support the static files serving for the **Website** service, and also included the essential boilerplate assets from the **HTML5 boilerplate** project. To provide further details about the work done: * Serving: Added the `FileMiddleware` middlewqare to the router; `path`, `server name`, and `log level` now read from config with defaults. * Library: Added the `StaticFile` enumeration with a `contentType` property, plus typed config-key/value constants and the `Configuration` dependency on WebsiteCore. * Assets: Added the **HTML5 boilerplate** (HTML, CSS, JS, icons, manifest, robots) to the *Resources/Static* folder. * Docker: Stage the Resources directory as read-only. * Tests: Added a test plan, and a shared Xcode scheme. Reviewed-on: rock-n-code/loud-amsterdam#3 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
70 lines
1.8 KiB
Swift
70 lines
1.8 KiB
Swift
import Configuration
|
|
import Foundation
|
|
import Hummingbird
|
|
import HummingbirdTesting
|
|
import Logging
|
|
import Testing
|
|
|
|
@testable import Website
|
|
@testable import WebsiteCore
|
|
|
|
@Suite("App executable")
|
|
struct AppTests {
|
|
|
|
// MARK: Constants
|
|
|
|
// Absolute path to the package's "Resources/Static" folder, derived from this
|
|
// file's location so the static files resolve regardless of the working directory.
|
|
private let staticFilesPath = URL(fileURLWithPath: #filePath)
|
|
.deletingLastPathComponent() // Tests/App
|
|
.deletingLastPathComponent() // Tests
|
|
.deletingLastPathComponent() // package root
|
|
.appendingPathComponent(.Path.staticResources)
|
|
.path
|
|
|
|
// MARK: Functional tests
|
|
|
|
@Test(arguments: StaticFile.allCases)
|
|
func `static files to be served`(
|
|
staticFile file: StaticFile
|
|
) async throws {
|
|
let app = try await application(
|
|
reader: reader(
|
|
staticFilesPath: staticFilesPath
|
|
)
|
|
)
|
|
|
|
try await app.test(.router) { client in
|
|
try await client.execute(
|
|
uri: "/\(file.relativePath)",
|
|
method: .get
|
|
) { response in
|
|
#expect(response.status == .ok)
|
|
#expect(response.headers[.contentType] == file.contentType)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private extension AppTests {
|
|
|
|
// MARK: Methods
|
|
|
|
func reader(
|
|
staticFilesPath: String
|
|
) -> ConfigReader {
|
|
ConfigReader(providers: [
|
|
InMemoryProvider(values: [
|
|
.HTTP.host: .HTTP.host,
|
|
.HTTP.port: .HTTP.port,
|
|
.Log.level: .Log.level,
|
|
.Path.staticFiles: .init(stringLiteral: staticFilesPath),
|
|
])
|
|
])
|
|
}
|
|
|
|
}
|