Added a new folder serve script demo.

This commit is contained in:
Relintai 2024-01-02 02:59:16 +01:00
parent 0e30f5f13a
commit 18918cf91e
3 changed files with 85 additions and 0 deletions

View File

@ -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 .`

View File

@ -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

View File

@ -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 .`