Skip to content

Commit

Permalink
fix: cors and sse for logs (#1284)
Browse files Browse the repository at this point in the history
Co-authored-by: Reece Williams <reecepbcups@gmail.com>
  • Loading branch information
frechg and Reecepbcups authored Oct 17, 2024
1 parent 5925ae7 commit 94f22e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions Dockerfile.local-interchain
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ RUN cd local-interchain && make build

RUN mv ./bin/local-ic /go/bin

# Reduces the size of the final image from 7GB -> 0.1GB
FROM busybox:1.35.0 AS final
# Final stage
FROM debian:bookworm-slim AS final

# Install certificates and required libraries
RUN apt-get update && \
apt-get install -y ca-certificates libc6 && \
update-ca-certificates && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/local/bin
COPY --from=builder /go/bin/local-ic /usr/local/bin/local-ic

EXPOSE 8080

# Run
CMD ["local-ic"]
CMD ["local-ic"]
2 changes: 1 addition & 1 deletion local-interchain/interchain/handlers/log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (ls *LogStream) StreamLogs(w http.ResponseWriter, r *http.Request) {
line, err := reader.ReadString('\n')
if err == nil {
// Send the log line to the client
fmt.Fprintf(w, "%s\n", line)
fmt.Fprintf(w, "data: %s\n\n", line)
flusher.Flush() // Send to client immediately
} else {
// If no new log is available, wait for a short period before retrying
Expand Down
2 changes: 1 addition & 1 deletion local-interchain/interchain/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func StartChain(installDir, chainCfgFile string, ac *types.AppStartConfig) {
// Where ORIGIN_ALLOWED is like `scheme://dns[:port]`, or `*` (insecure)
corsHandler := handlers.CORS(
handlers.AllowedOrigins([]string{"*"}),
handlers.AllowedHeaders([]string{"*"}),
handlers.AllowedHeaders([]string{"Content-Type", "Authorization", "Accept"}),
handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS", "DELETE"}),
handlers.AllowCredentials(),
handlers.ExposedHeaders([]string{"*"}),
Expand Down

0 comments on commit 94f22e6

Please sign in to comment.