From 16ebc504815a0eed206279122a51f625309c39df Mon Sep 17 00:00:00 2001 From: Andrea Giammarchi Date: Mon, 14 Apr 2025 15:55:10 +0200 Subject: [PATCH] Fix #2326 - Redirect to localhost when on 0.0.0.0 (#2328) * Fix #2326 - Redirect to localhost when on 0.0.0.0 --- core/src/core.js | 1 + core/src/zero-redirect.js | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 core/src/zero-redirect.js diff --git a/core/src/core.js b/core/src/core.js index e8bdf7e9..83e7734b 100644 --- a/core/src/core.js +++ b/core/src/core.js @@ -1,5 +1,6 @@ /*! (c) PyScript Development Team */ +import "./zero-redirect.js"; import stickyModule from "sticky-module"; import "@ungap/with-resolvers"; diff --git a/core/src/zero-redirect.js b/core/src/zero-redirect.js new file mode 100644 index 00000000..ddc34f73 --- /dev/null +++ b/core/src/zero-redirect.js @@ -0,0 +1,7 @@ +/* eslint no-unused-vars: 0 */ +try { + crypto.randomUUID(); +} catch (_) { + if (location.href.startsWith("http://0.0.0.0")) + location.href = location.href.replace("0.0.0.0", "localhost"); +}