mirror of
https://github.com/Relintai/pandemonium_demo_projects.git
synced 2024-12-21 13:56:50 +01:00
Added a new folder serve script demo.
This commit is contained in:
parent
0e30f5f13a
commit
18918cf91e
12
web_standalone_scripts/folder_serve/README.md
Normal file
12
web_standalone_scripts/folder_serve/README.md
Normal 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 .`
|
||||||
|
|
||||||
|
|
61
web_standalone_scripts/folder_serve/folder_serve.gd
Normal file
61
web_standalone_scripts/folder_serve/folder_serve.gd
Normal 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
|
||||||
|
|
12
web_standalone_scripts/folder_serve/test/README.md
Normal file
12
web_standalone_scripts/folder_serve/test/README.md
Normal 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 .`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user