mirror of
https://github.com/Relintai/pandemonium_cms.git
synced 2024-11-12 09:35:02 +01:00
Added a simple web server to the static exporter to serve the resulting folder for tests.
This commit is contained in:
parent
1b57ced921
commit
739c909ad4
@ -113,3 +113,4 @@ func _on_ExportButton_pressed() -> void:
|
||||
|
||||
func _on_OpenFolderButton_pressed() -> void:
|
||||
OS.shell_open(OS.get_user_data_dir())
|
||||
|
||||
|
@ -1,36 +1,61 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://WebRoot.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://StaticMain.gd" type="Script" id=2]
|
||||
[ext_resource path="res://StaticWebServerSimple.gd" type="Script" id=3]
|
||||
[ext_resource path="res://StaticMainNode.gd" type="Script" id=4]
|
||||
[ext_resource path="res://WebRoot.gd" type="Script" id=5]
|
||||
|
||||
[node name="StaticMain" type="WebServer"]
|
||||
[node name="StaticMain" type="Node"]
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="StaticMain" type="WebServer" parent="."]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="WebRoot" parent="." instance=ExtResource( 1 )]
|
||||
[node name="WebRoot" parent="StaticMain" instance=ExtResource( 1 )]
|
||||
www_root_path = "res://www/"
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
[node name="PanelContainer" type="PanelContainer" parent="StaticMain"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="StaticMain/PanelContainer"]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 593.0
|
||||
alignment = 1
|
||||
|
||||
[node name="ExportButton" type="Button" parent="PanelContainer/VBoxContainer"]
|
||||
margin_top = 271.0
|
||||
[node name="ExportButton" type="Button" parent="StaticMain/PanelContainer/VBoxContainer"]
|
||||
margin_top = 255.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 291.0
|
||||
margin_bottom = 275.0
|
||||
text = "Export"
|
||||
|
||||
[node name="OpenFolderButton" type="Button" parent="PanelContainer/VBoxContainer"]
|
||||
margin_top = 295.0
|
||||
[node name="OpenFolderButton" type="Button" parent="StaticMain/PanelContainer/VBoxContainer"]
|
||||
margin_top = 279.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 315.0
|
||||
margin_bottom = 299.0
|
||||
text = "Open Export Folder"
|
||||
|
||||
[connection signal="pressed" from="PanelContainer/VBoxContainer/ExportButton" to="." method="_on_ExportButton_pressed"]
|
||||
[connection signal="pressed" from="PanelContainer/VBoxContainer/OpenFolderButton" to="." method="_on_OpenFolderButton_pressed"]
|
||||
[node name="HSeparator" type="HSeparator" parent="StaticMain/PanelContainer/VBoxContainer"]
|
||||
margin_top = 303.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 307.0
|
||||
|
||||
[node name="ServeON" type="Button" parent="StaticMain/PanelContainer/VBoxContainer"]
|
||||
margin_top = 311.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 331.0
|
||||
text = "Serve Exported Folder ON"
|
||||
|
||||
[node name="WebServerSimple" type="WebServerSimple" parent="."]
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="WebRoot" type="WebRoot" parent="WebServerSimple"]
|
||||
routing_enabled = false
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[connection signal="pressed" from="StaticMain/PanelContainer/VBoxContainer/ExportButton" to="StaticMain" method="_on_ExportButton_pressed"]
|
||||
[connection signal="pressed" from="StaticMain/PanelContainer/VBoxContainer/OpenFolderButton" to="StaticMain" method="_on_OpenFolderButton_pressed"]
|
||||
[connection signal="pressed" from="StaticMain/PanelContainer/VBoxContainer/ServeON" to="." method="_on_ServeON_pressed"]
|
||||
|
6
game/StaticMainNode.gd
Normal file
6
game/StaticMainNode.gd
Normal file
@ -0,0 +1,6 @@
|
||||
extends Node
|
||||
|
||||
|
||||
func _on_ServeON_pressed() -> void:
|
||||
$WebServerSimple.start()
|
||||
|
9
game/StaticWebServerSimple.gd
Normal file
9
game/StaticWebServerSimple.gd
Normal file
@ -0,0 +1,9 @@
|
||||
extends WebServerSimple
|
||||
|
||||
|
||||
|
||||
|
||||
func _start() -> void:
|
||||
get_node("WebRoot").www_root_path = OS.get_user_data_dir().append_path("export/")
|
||||
|
||||
._start()
|
47
game/WebRoot.gd
Normal file
47
game/WebRoot.gd
Normal file
@ -0,0 +1,47 @@
|
||||
extends WebRoot
|
||||
|
||||
func _handle_request_main(request : WebServerRequest) -> void:
|
||||
#if (process_middlewares(request)):
|
||||
# return;
|
||||
|
||||
#if (web_permission.is_valid()):
|
||||
# if (web_permission.activate(request)):
|
||||
# return;
|
||||
|
||||
#handle_request(request);
|
||||
|
||||
# handle files first
|
||||
if (try_send_wwwroot_file_gd(request)):
|
||||
return;
|
||||
|
||||
handle_request(request);
|
||||
|
||||
# normal routing
|
||||
# if (!routing_enabled):
|
||||
# handle_request(request);
|
||||
# return;
|
||||
#
|
||||
# if (!try_route_request_to_children(request)):
|
||||
# handle_request(request);
|
||||
|
||||
func try_send_wwwroot_file_gd(request : WebServerRequest) -> bool:
|
||||
var path : String = request.get_path_full();
|
||||
path = path.to_lower();
|
||||
|
||||
var file_indx : int = www_root_file_cache.wwwroot_get_file_index(path);
|
||||
|
||||
if (file_indx != -1):
|
||||
send_file(www_root_file_cache.wwwroot_get_file_orig_path(file_indx), request);
|
||||
|
||||
return true;
|
||||
else:
|
||||
path = path.plus_file("index.html")
|
||||
|
||||
file_indx = www_root_file_cache.wwwroot_get_file_index(path);
|
||||
|
||||
if (file_indx != -1):
|
||||
send_file(www_root_file_cache.wwwroot_get_file_orig_path(file_indx), request);
|
||||
|
||||
return true;
|
||||
|
||||
return false;
|
Loading…
Reference in New Issue
Block a user