How do I bind the http server address to 0.0.0.0

Godot Version

4.5

Question

I want to make an HTML game that I can test across multiple devices. The easiest way to do it is to run it on a server binded to 0.0.0.0

Godot allows me run a game using “Run in Browser” but this is binded to “localhost” only. So any requests coming in from another device in the same network is rejected.

The workaround I can think is to do an export html to file system and then start a local http server using some other software. This is a pain.

Why not upload it to a webserver? You might even want to look into uploading it at itch.io

I’d go for the local webserver route, but then Linux is my desktop system and I have dozens on webapps running in docker containers.

1 Like

You can connect to a “Run in Browser”/“Start HTTP Server” debugging session from another device, I’ve done this to test HTML mobile games and HTML VR games. Can you explain how exactly you are trying to do so?

It would work of course, wont it be a nightmare for prototyping ?
I’m curious on the pipeline here for just one line of code change …

  • Make one line of code change
  • Export html
  • Zip the folder with html contents (yes itch io requires a zip file)
  • Open itch io, upload it.
  • After uploading, itch io forces you to click : This runs in a browser
  • Click publish

Isn’t that too many steps for one line of code change ?

Interesting, how do I do that ?
Clicking “Run in Browser” starts the application on “http://localhost:8060/tmp_js_export.html”

What do I do with my device on the same WIFI lan ?

Hi salvin18!

It is quite easy to set up Itch.io and Godot in a way which publishes your game with one button click from inside Godot to Itch. But one would not publish to Itch after changing one line of code, but only for major releases.

If you run something on a server you would probably have to configure Apache or nginx in the long run. Itch lets you host games without having to know anything about server configuration of networking.

Godot allows you to export your games for many platforms, the web is only one option (next to iOS, Android, Linux, Mac, Windows). But when doing such exports you would actually write your game in Godot and never have to touch on HTML or JavaScript. You would write your game in Godot and the export option would handle the rest (see documentation on export options).

If your game does not require it or if you don’t explicitly want to learn these technologies, I can highly recommend exporting directly from Godot to Itch. It really is quite easy once setup correctly.

Kind regards :four_leaf_clover:

localhost means “the computer this web browser is running on” You need to find your local ip address, if on windows the command line utility ipconfig will show it, on linux ip addr will do the same. You must enter your server machine’s ip address into your other device, for example
http://192.168.1.123:8060/tmp_js_export.html

2 Likes

Does that actually work ? I am surprised. On my linux machine it does not work with local ip address. I see a “refused to connect.” error.

I was thinking of hosting my own webserver on local instead

What did you type into the address bar?
Is the HTTP server running on the correct machine?

I executed “ip addr“ on my desktop to get the ip address, then I open browser on the same machine.
”localhost works, My IP address does not work.

I am using linux mint

What did you enter specifically? On the same machine you can continue to use localhost if you please

Maybe put your local IP address into this editor settings field “export/web/http_host”

There’s some progress… now machine ip works but the site does not load:

The following features required to run Godot projects on the Web are missing:
Secure Context - Check web server configuration (use HTTPS)

Next, on my other devices on the same network, it does not load it at all, browser is stuck

I do this all the time in game jams. Especially the alst day. I fix a bug, upload it, test it. The key to this is to use butler. You can download it for free on itch. The benefit is it creates a patch and only uploads that patch. So if you only change a line of code, 1% or less of your code is actually getting pushed up. You lso can declare in the upload it is for web, and it does all the fiddly bits for you.

1 Like

Here’s a python script you can use to run a server on your box.

Web Server Python Script
#!/usr/bin/env python3

import argparse
import contextlib
import os
import socket
import subprocess
import sys
from http.server import HTTPServer, SimpleHTTPRequestHandler, test  # type: ignore
from pathlib import Path


# See cpython GH-17851 and GH-17864.
class DualStackServer(HTTPServer):
    def server_bind(self):
        # Suppress exception when protocol is IPv4.
        with contextlib.suppress(Exception):
            self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
        return super().server_bind()


class CORSRequestHandler(SimpleHTTPRequestHandler):
    def end_headers(self):
        self.send_header("Cross-Origin-Opener-Policy", "same-origin")
        self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
        self.send_header("Access-Control-Allow-Origin", "*")
        super().end_headers()


def shell_open(url):
    if sys.platform == "win32":
        os.startfile(url)
    else:
        opener = "open" if sys.platform == "darwin" else "xdg-open"
        subprocess.call([opener, url])


def serve(root, port, run_browser):
    os.chdir(root)

    if run_browser:
        # Open the served page in the user's default browser.
        print("Opening the served URL in the default browser (use `--no-browser` or `-n` to disable this).")
        shell_open(f"http://127.0.0.1:{port}")

    test(CORSRequestHandler, DualStackServer, port=port)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-p", "--port", help="port to listen on", default=8060, type=int)
    parser.add_argument(
        "-r", "--root", help="path to serve as root (relative to `platform/web/`)", default="../../bin", type=Path
    )
    browser_parser = parser.add_mutually_exclusive_group(required=False)
    browser_parser.add_argument(
        "-n", "--no-browser", help="don't open default web browser automatically", dest="browser", action="store_false"
    )
    parser.set_defaults(browser=True)
    args = parser.parse_args()

    # Change to the directory where the script is located,
    # so that the script can be run from any location.
    os.chdir(Path(__file__).resolve().parent)

    serve(args.root, args.port, args.browser)

On Windows you can use this batch script to run it:

 REM Place this file and serve.py into the folder with an exported Godot HTML file to test it.
 REM Double-click this to launch the test server.
 start powershell -command "python serve.py --root ."

On linux just make a shell script to run it.

python3 serve.py --root .

You may have to play with the shell command, it’s been a few years since I’ve used Linux and I just guessed at it..

1 Like

P.S. Putting your server on 0.0.0.0 is a really bad idea. It’s a special IP and will take a connection from anything your computer is connected to. It’s really useful backdoor for hackers.

This is only half true.
If you’re sitting behind a firewall on a local network, and you have no port forwarding or DMZ set up, then the outside world has no access to your PC still, so you’re fine. And I imagine that’s likely the case here, this is (hopefully) not for production use.

2 Likes

The usecase is for development only not production release

As long as you are behind a firewall and trust everyone you punch a hole through the firewall for, you will not have any problems.