Skip to content
Snippets Groups Projects
Verified Commit 4c063b74 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: commit save point

parent 29a54dc7
No related branches found
No related tags found
No related merge requests found
#############################################################################################
#############################################################################################
##
## PROJECT-DEFINITIONS
##
#############################################################################################
#############################################################################################
COMPONENT_NAME := Monster
#############################################################################################
#############################################################################################
##
## MORE GENERAL BLOCK WITH STANDARD DEFINITIONS
##
#############################################################################################
#############################################################################################
# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
PROJECT_ROOT:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)/
THIS_MAKEFILE:=$(PROJECT_ROOT)$(THIS_MAKEFILE_PATH)
-include $(PROJECT_ROOT)project.mk
## Define the location of Makefiles
MAKEFILE_IMPORT_PATH?=$(PROJECT_ROOT)makefiles/
-include $(MAKEFILE_IMPORT_PATH)project.mk
#############################################################################################
#############################################################################################
##
## INCLUSION OF VARIOUS STANDARD RULES
##
#############################################################################################
#############################################################################################
include $(MAKEFILE_IMPORT_PATH)directories-standard.mk
#include $(MAKEFILE_IMPORT_PATH)jsdoc.mk
include $(MAKEFILE_IMPORT_PATH)output.mk
include $(MAKEFILE_IMPORT_PATH)placeholder.mk
#include $(MAKEFILE_IMPORT_PATH)s3.mk
#include $(MAKEFILE_IMPORT_PATH)license-agpl3.mk
#include $(MAKEFILE_IMPORT_PATH)jsdoc-json.mk
#include $(MAKEFILE_IMPORT_PATH)go.mk
include $(MAKEFILE_IMPORT_PATH)gitignore.mk
include $(MAKEFILE_IMPORT_PATH)color.mk
include $(MAKEFILE_IMPORT_PATH)version.mk
#include $(MAKEFILE_IMPORT_PATH)node.mk
include $(MAKEFILE_IMPORT_PATH)terminal.mk
#include $(MAKEFILE_IMPORT_PATH)target-go-fetch-licenses.mk
#include $(MAKEFILE_IMPORT_PATH)target-deploy-tool.mk
#include $(MAKEFILE_IMPORT_PATH)target-jsdoc-build.mk
#include $(MAKEFILE_IMPORT_PATH)target-jekyll.mk
#include $(MAKEFILE_IMPORT_PATH)target-minerva.mk
#include $(MAKEFILE_IMPORT_PATH)target-docman.mk
#include $(MAKEFILE_IMPORT_PATH)target-node-build.mk
#include $(MAKEFILE_IMPORT_PATH)target-caddy.mk
include $(MAKEFILE_IMPORT_PATH)target-update-makefiles.mk
include $(MAKEFILE_IMPORT_PATH)target-help.mk
#include $(MAKEFILE_IMPORT_PATH)target-go-build.mk
#include $(MAKEFILE_IMPORT_PATH)target-node-test.mk
#include $(MAKEFILE_IMPORT_PATH)target-npm-publish.mk
include $(MAKEFILE_IMPORT_PATH)target-git.mk
include $(MAKEFILE_IMPORT_PATH)target-init-standard.mk
include $(MAKEFILE_IMPORT_PATH)target-variable.mk
include $(MAKEFILE_IMPORT_PATH)terminal-check.mk
#############################################################################################
......@@ -10,3 +10,5 @@ const AppStyleDirectory = "styles"
const AppScriptDirectory = "scripts"
const StandardCacheControl = "no-cache, no-store, must-revalidate"
const WebsocketPath = "/websocketPath"
package server
import (
"net/http"
"time"
)
var epoch = time.Unix(0, 0).Format(time.RFC1123)
var noCacheHeaders = map[string]string{
"Expires": epoch,
"Cache-Control": "no-cache, private, max-age=0",
"Pragma": "no-cache",
"X-Accel-Expires": "0",
}
var etagHeaders = []string{
"ETag",
"If-Modified-Since",
"If-Match",
"If-None-Match",
"If-Range",
"If-Unmodified-Since",
}
func NoCache(h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
// Delete any ETag headers that may have been set
for _, v := range etagHeaders {
if r.Header.Get(v) != "" {
r.Header.Del(v)
}
}
// Set our NoCache headers
for k, v := range noCacheHeaders {
w.Header().Set(k, v)
}
h.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
package server
import (
"gitlab.schukai.com/oss/utilities/conan/configuration"
"gitlab.schukai.com/oss/utilities/conan/constants"
"gitlab.schukai.com/oss/utilities/conan/logging"
"net/http"
"os"
"regexp"
"strings"
)
func injectHandler(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, ".html") {
path := configuration.GetServerWebPath() + "/" + r.URL.Path
p, err := os.ReadFile(path)
if err != nil {
logging.LogError("injectHandler error %s", err.Error())
return
}
p = injectScript(p)
w.Header().Set("Content-Type", "text/html")
w.Write(p)
return
}
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}
var script string
func init() {
script = `<head>
<script type="module">
try {
let counter = 0;
let socket
let url = ""
if (document.location.protocol == 'https:') {
url = 'wss://'
} else {
url = 'ws://'
}
url += document.location.host + "{{ constants.WebsocketPath }}";
function connectWebsocket() {
if (socket) {
socket.close()
}
if (counter++ > 20) {
console.error("Failed 20 times to connect to websocket. Giving up.")
return
}
socket = new WebSocket(url)
socket.onopen = function (e) {
console.log("[conan] Connection established");
counter = 0
};
socket.onmessage = function (event) {
console.log("[conan] Data received from server: " + event?.data);
if (event?.data == "reload") {
console.log("[conan] Reloading page")
window.location.reload();
}
};
socket.onclose = function (event) {
if (event.wasClean) {
console.log("[conan] Connection closed cleanly, code=" + event?.code + " reason=" + event?.reason + "");
} else {
console.error("[conan] Connection died");
setTimeout(connectWebsocket, 3000*counter)
}
};
socket.onerror = function (error) {
console.error("[conan] " + error?.message);
};
}
document.addEventListener("DOMContentLoaded", () => {
connectWebsocket()
})
} catch (e) {
console.error(e)
}
</script>`
script = strings.Replace(script, "{{ constants.WebsocketPath }}", constants.WebsocketPath, -1)
}
func injectScript(p []byte) []byte {
s := string(p)
reg := regexp.MustCompile(`<head>`)
s = reg.ReplaceAllString(s, script)
return []byte(s)
}
......@@ -2,11 +2,14 @@ package server
import (
"crypto/tls"
"gitea.com/go-chi/session"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"gitlab.schukai.com/oss/utilities/conan/configuration"
"gitlab.schukai.com/oss/utilities/conan/constants"
"gitlab.schukai.com/oss/utilities/conan/header"
"gitlab.schukai.com/oss/utilities/conan/logging"
"gitlab.schukai.com/oss/utilities/conan/websocket"
"net/http"
)
......@@ -25,12 +28,16 @@ func getRouter() *chi.Mux {
router.Use(middleware.Compress(5))
router.Use(logging.LoggerMiddleware)
router.Use(reloadMiddleware)
router.Use(NoCache)
router.Handle("/*", http.FileServer(
http.Dir(configuration.GetServerWebPath()+"/")))
router.Use(session.Sessioner())
return router
router.Handle(constants.WebsocketPath, websocket.GetWebsocketHandler())
}
//fs := NoListFileSystem{http.Dir(configuration.GetServerWebPath() + "/")}
// router.Handle("*.html", injectHandler(http.FileServer(http.Dir(configuration.GetServerWebPath()+"/"))))
router.Handle("/*", injectHandler(http.FileServer(http.Dir(configuration.GetServerWebPath()+"/"))))
return router
}
......@@ -7,6 +7,7 @@ import (
"gitlab.schukai.com/oss/utilities/conan/configuration"
"gitlab.schukai.com/oss/utilities/conan/constants"
"gitlab.schukai.com/oss/utilities/conan/logging"
"gitlab.schukai.com/oss/utilities/conan/websocket"
"os"
"path"
"path/filepath"
......@@ -65,6 +66,12 @@ func executeWatchAction(watchPath string) {
}
}
if w.Command == "" {
logging.LogInfo("watching: no command defined for %s", watchPath)
websocket.SendReloadMessage()
continue
}
logging.LogDebug("watching: execute watch action: %s", w.Command)
t, err := template.New("command").Parse(w.Command)
......@@ -109,6 +116,8 @@ func executeWatchAction(watchPath string) {
r, err := result.String()
logging.LogDebug("%s", r)
websocket.SendReloadMessage()
if err != nil {
logging.LogError("watching: execute watch action error: %v", err.Error())
continue
......
......@@ -14,20 +14,6 @@ var (
connections = make(map[string]*websocket.Conn)
)
//func getCmd(input string) string {
// inputArr := strings.Split(input, " ")
// return inputArr[0]
//}
//
//func getMessage(input string) string {
// inputArr := strings.Split(input, " ")
// var result string
// for i := 1; i < len(inputArr); i++ {
// result += inputArr[i]
// }
// return result
//}
func SendMessageToAll(message []byte) {
for _, conn := range connections {
......@@ -45,6 +31,10 @@ func closeConnection(session string) error {
return nil
}
func SendReloadMessage() {
SendMessageToAll([]byte("reload"))
}
func GetWebsocketHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
......@@ -69,11 +59,6 @@ func GetWebsocketHandler() http.Handler {
closeConnection(session)
}()
//if sessionStore.Get("user") == nil {
// http.Error(w, "Forbidden", http.StatusForbidden)
// return
//}
// Continuosly read and write message
for {
mt, message, err := conn.ReadMessage()
......@@ -87,25 +72,6 @@ func GetWebsocketHandler() http.Handler {
}
fmt.Println(mt, string(message), "!!!!!!!!!!!!!!!!!!")
//input := string(message)
//cmd := getCmd(input)
//msg := getMessage(input)
//if cmd == "x" {
// todoList = append(todoList, msg)
//} else if cmd == "done" {
// updateTodoList(msg)
//}
//output := "Current Todos: \n"
//for _, todo := range todoList {
// output += "\n - " + todo + "\n"
//}
//output += "\n----------------------------------------"
//message = []byte(output)
//err = conn.WriteMessage(mt, message)
//if err != nil {
// log.Println("write failed:", err)
// break
//}
}
})
}
......@@ -22,6 +22,10 @@ Server:
Exclude:
- ~$
- ^\.
- Path: web
Exclude:
- ~$
- ^\.
Flags:
FollowSymlinks: true
......
console.log('Hello ME!?');
\ No newline at end of file
document.addEventListener("DOMContentLoaded", () => {
document.querySelector("#app").innerHTML = "Hello!!! World?!";
})
// Language: javascript
\ No newline at end of file
......@@ -6,5 +6,8 @@
<script src="scripts/bundle.js"></script>
</head>
<body>
<h1>Hello World</h1>
<h1>Hello ...ddd</h1>
<div id="app"></div>
</body>
(() => {
// src/main.js
console.log("Hello ME!?");
document.addEventListener("DOMContentLoaded", () => {
document.querySelector("#app").innerHTML = "Hello!!! World?!";
});
})();
//# sourceMappingURL=bundle.js.map
{
"version": 3,
"sources": ["../../src/main.js"],
"sourcesContent": ["console.log('Hello ME!?');"],
"mappings": ";;AAAA,UAAQ,IAAI,YAAY;",
"sourcesContent": ["document.addEventListener(\"DOMContentLoaded\", () => {\n document.querySelector(\"#app\").innerHTML = \"Hello!!! World?!\";\n})\n// Language: javascript "],
"mappings": ";;AAAA,WAAS,iBAAiB,oBAAoB,MAAM;AAChD,aAAS,cAAc,MAAM,EAAE,YAAY;AAAA,EAC/C,CAAC;",
"names": []
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment