Skip to content

Instantly share code, notes, and snippets.

@nisovin
nisovin / Godot Web Server Configs.md
Last active May 23, 2024 22:07
Godot Web Server Configs

Godot Web Server Configs

For Godot 4 and the threads export in Godot 3, you need to set special headers on your web server in order to enable SharedArrayBuffer. There are some examples here for various web servers.

Python

The script below can be used to start a web server that sets the required headers. The easiest way to use this is to place this python script in your export folder and double click it to start the server. Then you can view your game at http://localhost:8000.

extends HTTPRequest
class_name HTTPFilePost
func post_file(url: String, field_name: String, file_name: String, file_path: String, post_fields: Dictionary = {}, content_type: String = "", custom_headers: Array = [], verify_ssl: bool = true):
var file = File.new()
file.open(file_path)
var content = file.get_buffer(file.get_len())
file.close()
post_data_as_file(url, field_name, file_name, content, post_fields, content_type, custom_headers, verify_ssl)
extends HTTPRequest
class_name HTTPFormPost
func example():
post_files("https://example.com", [
FileDef.new().from_file("user://test.txt", "file")
], {
"other_field": "test"
})