Re-read custom `index.html` on updates (#342)
We were reading custom `index.html` only once on launch, which meant people had to restart `carton dev` every time they've updated `index.html` during the build process to see changes they've made.
This commit is contained in:
parent
1ba7dd5d82
commit
c834751074
|
@ -18,7 +18,7 @@ jobs:
|
|||
swift_version: 5.5
|
||||
xcode: /Applications/Xcode_13.2.1.app/Contents/Developer
|
||||
- os: ubuntu-20.04
|
||||
swift_version: 5.5
|
||||
swift_version: 5.6
|
||||
name: Build on ${{ matrix.os }} with Swift ${{ matrix.swift_version }}
|
||||
timeout-minutes: 40
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
|
|
@ -127,7 +127,7 @@ struct Dev: AsyncParsableCommand {
|
|||
shouldSkipAutoOpen: skipAutoOpen,
|
||||
port: port,
|
||||
host: host,
|
||||
customIndexContent: HTML.readCustomIndexPage(at: customIndexPage, on: localFileSystem),
|
||||
customIndexPath: customIndexPage.map { AbsolutePath($0, relativeTo: localFileSystem.currentWorkingDirectory!) },
|
||||
// swiftlint:disable:next force_try
|
||||
manifest: try! toolchain.manifest.get(),
|
||||
product: build.product,
|
||||
|
|
|
@ -39,7 +39,7 @@ struct BrowserTestRunner: TestRunner {
|
|||
shouldSkipAutoOpen: false,
|
||||
port: port,
|
||||
host: host,
|
||||
customIndexContent: nil,
|
||||
customIndexPath: nil,
|
||||
manifest: manifest,
|
||||
product: nil,
|
||||
entrypoint: Constants.entrypoint,
|
||||
|
|
|
@ -24,7 +24,7 @@ extension Application {
|
|||
let port: Int
|
||||
let host: String
|
||||
let mainWasmPath: AbsolutePath
|
||||
let customIndexContent: String?
|
||||
let customIndexPath: AbsolutePath?
|
||||
let manifest: Manifest
|
||||
let product: ProductDescription?
|
||||
let entrypoint: Entrypoint
|
||||
|
@ -43,12 +43,21 @@ extension Application {
|
|||
middleware.use(FileMiddleware(publicDirectory: directory))
|
||||
|
||||
// register routes
|
||||
get { _ in
|
||||
get { (request: Request) -> EventLoopFuture<HTML> in
|
||||
let customIndexContent: EventLoopFuture<String?>
|
||||
if let path = configuration.customIndexPath?.pathString {
|
||||
customIndexContent = request.fileio.collectFile(at: path).map { String(buffer: $0) }
|
||||
} else {
|
||||
customIndexContent = request.eventLoop.makeSucceededFuture(nil)
|
||||
}
|
||||
|
||||
return customIndexContent.map {
|
||||
HTML(value: HTML.indexPage(
|
||||
customContent: configuration.customIndexContent,
|
||||
customContent: $0,
|
||||
entrypointName: configuration.entrypoint.fileName
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
webSocket("watcher") { request, ws in
|
||||
let environment = request.headers["User-Agent"].compactMap(DestinationEnvironment.init).first
|
||||
|
|
|
@ -34,9 +34,7 @@ extension HTML: ResponseEncodable {
|
|||
))
|
||||
}
|
||||
|
||||
public static func readCustomIndexPage(at path: String?,
|
||||
on fileSystem: FileSystem) throws -> String?
|
||||
{
|
||||
public static func readCustomIndexPage(at path: String?, on fileSystem: FileSystem) throws -> String? {
|
||||
if let customIndexPage = path {
|
||||
let content = try localFileSystem.readFileContents(customIndexPage.isAbsolutePath ?
|
||||
AbsolutePath(customIndexPage) :
|
||||
|
|
|
@ -95,7 +95,7 @@ public actor Server {
|
|||
let shouldSkipAutoOpen: Bool
|
||||
let port: Int
|
||||
let host: String
|
||||
let customIndexContent: String?
|
||||
let customIndexPath: AbsolutePath?
|
||||
let manifest: Manifest
|
||||
let product: ProductDescription?
|
||||
let entrypoint: Entrypoint
|
||||
|
@ -108,7 +108,7 @@ public actor Server {
|
|||
shouldSkipAutoOpen: Bool,
|
||||
port: Int,
|
||||
host: String,
|
||||
customIndexContent: String?,
|
||||
customIndexPath: AbsolutePath?,
|
||||
manifest: Manifest,
|
||||
product: ProductDescription?,
|
||||
entrypoint: Entrypoint,
|
||||
|
@ -120,7 +120,7 @@ public actor Server {
|
|||
self.shouldSkipAutoOpen = shouldSkipAutoOpen
|
||||
self.port = port
|
||||
self.host = host
|
||||
self.customIndexContent = customIndexContent
|
||||
self.customIndexPath = customIndexPath
|
||||
self.manifest = manifest
|
||||
self.product = product
|
||||
self.entrypoint = entrypoint
|
||||
|
@ -147,7 +147,7 @@ public actor Server {
|
|||
port: configuration.port,
|
||||
host: configuration.host,
|
||||
mainWasmPath: configuration.mainWasmPath,
|
||||
customIndexContent: configuration.customIndexContent,
|
||||
customIndexPath: configuration.customIndexPath,
|
||||
manifest: configuration.manifest,
|
||||
product: configuration.product,
|
||||
entrypoint: configuration.entrypoint,
|
||||
|
|
Loading…
Reference in New Issue