Verified Commit ae9c3b96 authored by Aral Balkan's avatar Aral Balkan
Browse files

Add status log route

parent 4f8636a5
......@@ -30,8 +30,21 @@ app = require './App'
Builder = require './Builder'
# For piping the logging out
spawn = require('child_process').spawn
{ EventEmitter } = require 'events'
WebConsole = new EventEmitter
history = ""
#
# Decorate stdout.write to capture console.log statements.
#
process.stdout.write = ((write) ->
return (string, encoding, fileDescriptor) ->
string = "#{new Date()}: #{string}"
history += string
WebConsole.emit 'log', string
write.apply process.stdout, arguments
)(process.stdout.write)
class GitlabWebhookServer
......@@ -86,11 +99,21 @@ class GitlabWebhookServer
# Default
express.get '/', (request, response) =>
if app.isRunningInProduction
tail = spawn 'dokku', ['logs', 'builder.better.fyi', '--tail']
tail.stdout.pipe response
else
response.redirect 'https://better.fyi'
#
# Show status log
#
response.writeHead 200
# Write out the head of the HTML file with some basic styling.
response.write "<html lang='en'><head><meta charset='utf-8'><title>Console</title></head><body style='font-family: \"Avenir Next\", \"Avenir\", sans_serif; padding-left:2.5%'><h1>Status Log</h1><div style='display: flex; flex-direction: column-reverse; overflow: auto; height: 90%; width: 97.5%; background-color: black; color: white; font-size: large;'><pre style='padding-left:2.5%'>\n"
# Write out the full history.
response.write history
# Listen for log messages and stream them.
WebConsole.on 'log', (message) ->
response.write(message)
#
# Web hook
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment