Skip to content

Commit

Permalink
update title of page based on config file; also disable cors for dev …
Browse files Browse the repository at this point in the history
…mode and rest call for syntax colors
  • Loading branch information
jdrews committed Jul 31, 2022
1 parent 7525c7a commit 88b69d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var (
defaultConfigFile []byte

upgrader = websocket.Upgrader{}

// Set this to false in prod builds. Only used to help in debugging so I can run the frontend on a hotloading npm start
disableCORS = true
)

func main() {
Expand All @@ -41,6 +44,13 @@ func main() {

e.Use(middleware.Logger())

// Disable the following in production. Using in development so I can `npm start` and dev the frontend. It bypasses CORS
if disableCORS {
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
}
c, _ := handlers.NewContainer()

// GetLogstationName - Get Logstation Name
Expand Down Expand Up @@ -99,7 +109,9 @@ func wshandler(c echo.Context, pubSub *pubsub.PubSub) error {
logger := logrus.New()
logger.SetOutput(os.Stdout)
// Disable the following line in production. Using in development so I can `npm start` and dev the frontend. It bypasses CORS
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
if disableCORS {
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
}
ws, err := upgrader.Upgrade(c.Response(), c.Request(), nil)
if err != nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions web/src/LogViewer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect} from 'react';
import './LogViewer.css';
import {
List,
Expand All @@ -9,8 +9,12 @@ import {
import "react-virtualized/styles.css";
import ReconnectingWebSocket from 'reconnecting-websocket';

const url = 'ws://' + window.location.host + '/ws';
const rws = new ReconnectingWebSocket(url);
//const wsurl = 'ws://' + window.location.host + '/ws'; //PROD //TODO: Set this to PROD before ship
//const url = window.location.protocol + "//" + window.location.host //PROD
const wsurl = 'ws://localhost:8884/ws' //DEV
const url = 'http://localhost:8884' //DEV

const rws = new ReconnectingWebSocket(wsurl);

const minRowHeight = 23;

Expand All @@ -23,6 +27,8 @@ export default class LogViewer extends React.Component {
lines: [],
scrollToIndex: 0,
atBottom: false,
title: "logstation",
syntaxColors: []
}

this._cache = new CellMeasurerCache({
Expand Down Expand Up @@ -93,6 +99,9 @@ export default class LogViewer extends React.Component {
}}
>
{this.state.lines[index]}
//TODO: Figure out how to wrap this in a color (div?) when it matches a regex
//TODO: Also read in the /settings/syntax and apply it
//TODO: Also set the server name based on the /settings/logstation-name
</div> )}
</CellMeasurer>

Expand Down Expand Up @@ -139,6 +148,15 @@ export default class LogViewer extends React.Component {
}

componentDidMount() {
fetch(url + "/settings/logstation-name")
.then(response => response.json())
.then(data => {
this.state.title=data.name
document.title = this.state.title
})
fetch(url + "/settings/syntax")
.then(response => response.json())
.then(data => this.state.syntaxColors=data)
this.connect();
}
}

0 comments on commit 88b69d5

Please sign in to comment.