Fix dev server to serve entrypoint file (#465)

The server served `~/.carton/static` directory but we no longer use the
directory. Instead, we now serve the entrypoint from in-memory buffer.
This commit is contained in:
Yuta Saito 2024-05-21 11:18:23 +09:00 committed by GitHub
parent 79d686b7cb
commit 078f1edf58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 7 deletions

View File

@ -71,6 +71,11 @@ final class ServerHTTPHandler: ChannelInboundHandler, RemovableChannelHandler {
bytes: localFileSystem.readFileContents(configuration.mainWasmPath).contents
)
)
case "/" + configuration.entrypoint.fileName:
response = StaticResponse(
contentType: "application/javascript",
body: ByteBuffer(bytes: configuration.entrypoint.content.contents)
)
default:
guard let staticResponse = try self.respond(context: context, head: head) else {
self.respond404(context: context)
@ -111,13 +116,7 @@ final class ServerHTTPHandler: ChannelInboundHandler, RemovableChannelHandler {
private func respond(context: ChannelHandlerContext, head: HTTPRequestHead) throws
-> StaticResponse?
{
var responders = [
self.makeStaticResourcesResponder(
baseDirectory: FileManager.default.homeDirectoryForCurrentUser
.appendingPathComponent(".carton")
.appendingPathComponent("static")
)
]
var responders: [(_ context: ChannelHandlerContext, _ uri: String) throws -> StaticResponse?] = []
let buildDirectory = configuration.mainWasmPath.parentDirectory
for directoryName in try localFileSystem.resourcesDirectoryNames(relativeTo: buildDirectory) {