diff --git a/web_standalone_scripts/folder_serve/README.md b/web_standalone_scripts/folder_serve/README.md new file mode 100644 index 0000000..7d5435b --- /dev/null +++ b/web_standalone_scripts/folder_serve/README.md @@ -0,0 +1,12 @@ +# Folder Serve Demo + +This is a small script that serves a simple folder structure as a static site. + +Similar to `python -m http.server` + +It's derived from the SceneTree, so you don't need to run this as a project, +instead you need to get the engine, and run it with the `-s` (`--script`) option like so: + +`./pandemonium -s ./folder_serve.gd .` + + diff --git a/web_standalone_scripts/folder_serve/folder_serve.gd b/web_standalone_scripts/folder_serve/folder_serve.gd new file mode 100644 index 0000000..65b8913 --- /dev/null +++ b/web_standalone_scripts/folder_serve/folder_serve.gd @@ -0,0 +1,61 @@ +# Run this script like: /pandemonium -s static_serve.gd test_site_1 + +#extends Node +extends SceneTree +class_name StaticServe + +var web_server_simple : WebServerSimple = null + +func setup(): + OS.low_processor_usage_mode = true + + var folder_path : String = "./" + + var cmdline_args : PoolStringArray = OS.get_cmdline_args() + + if cmdline_args.size() > 0: + folder_path = cmdline_args[cmdline_args.size() - 1].path_ensure_end_slash() + + var dir : Directory = Directory.new() + + if !dir.dir_exists(folder_path): + folder_path = "./" + + var fswp : BrowsableFolderServeWebPage = BrowsableFolderServeWebPage.new() + fswp.serve_folder = folder_path + + web_server_simple = WebServerSimple.new() + web_server_simple.start_on_ready = true + web_server_simple.add_child(fswp) + + +# If it's a Node +#func _ready() -> void: +# setup() +# add_child(web_server_simple) + +# If it's a SceneTree +func _initialize(): + setup() + root.add_child(web_server_simple) + + var link0 : String = "http://" + web_server_simple.bind_host + ":" + str(web_server_simple.bind_port) + var link1 : String = "http://127.0.0.1:" + str(web_server_simple.bind_port) + + var run_text : String = "Running server on: " + link1 + " (" + link0 + ")" + + PLogger.log_message(run_text) + + #For the lolz + var pc : PanelContainer = PanelContainer.new() + root.add_child(pc) + pc.set_anchors_and_margins_preset(Control.PRESET_WIDE) + + var cc : CenterContainer = CenterContainer.new() + pc.add_child(cc) + + var lb : LinkButton = LinkButton.new() + cc.add_child(lb) + lb.uri = link1 + lb.text = run_text + diff --git a/web_standalone_scripts/folder_serve/test/README.md b/web_standalone_scripts/folder_serve/test/README.md new file mode 100644 index 0000000..4cf70fd --- /dev/null +++ b/web_standalone_scripts/folder_serve/test/README.md @@ -0,0 +1,12 @@ +# Static Serve Demo + +This is a small script that serves a simple folder structure as a static site. + +Similar to `python -m http.server` + +It's derived from the SceneTree, so you don't need to run this as a project, +instead you need to get the engine, and run it with the `-s` (`--script`) option like so: + +`./pandemonium -s ./folder_serve.gd .` + +