From 5a8aa6698e53f1e0b04899b6a4c1a869b5ab003b Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Mon, 6 May 2024 20:37:51 -0500 Subject: [PATCH] bare-mux support --- .gitignore | 4 +++- esbuild.dev.js | 22 ++++++++++++++++------ package.json | 3 ++- src/scramjet.config.ts | 2 -- src/worker/index.ts | 4 ++-- static/index.html | 16 ++++++++++++---- static/sw.js | 1 + 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 9322381..af11814 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ node_modules dist -static/scramjet* \ No newline at end of file +static/scramjet* +static/bare-mux.js +static/bare-client.js \ No newline at end of file diff --git a/esbuild.dev.js b/esbuild.dev.js index 56cf2e5..b984c43 100644 --- a/esbuild.dev.js +++ b/esbuild.dev.js @@ -17,10 +17,20 @@ const devServer = createServer({ plugins: [ copy({ resolveFrom: "cwd", - assets: { - from: ["./dist/*"], - to: ["./static"] - } + assets: [ + { + from: ['./node_modules/@mercuryworkshop/bare-mux/dist/bare.cjs'], + to: ['./static/bare-mux.js'], + }, + { + from: ['./node_modules/@mercuryworkshop/bare-as-module3/dist/bare.cjs'], + to: ['./static/bare-client.js'], + }, + { + from: ["./dist/*"], + to: ["./static"] + }, + ], }), time() ] @@ -28,8 +38,8 @@ const devServer = createServer({ static: "./static", port: 1337, proxy: (path) => { - if (path.startsWith("/bare")) { - return path.replace("/bare", "http://127.0.0.1:3000") + if (path.startsWith("/bare/")) { + return path.replace("/bare/", "http://127.0.0.1:3000/") } }, injectLiveReload: false diff --git a/package.json b/package.json index 4f80d0a..39cfdf6 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "type": "module", "dependencies": { "@fastify/static": "^7.0.3", - "@tomphttp/bare-client": "2.2.0-alpha", + "@mercuryworkshop/bare-mux": "^1.1.0", + "@mercuryworkshop/bare-as-module3": "^2.2.0-alpha", "@tomphttp/bare-server-node": "^2.0.3", "concurrently": "^8.2.2", "dom-serializer": "^2.0.0", diff --git a/src/scramjet.config.ts b/src/scramjet.config.ts index abad16f..10d7aec 100644 --- a/src/scramjet.config.ts +++ b/src/scramjet.config.ts @@ -4,7 +4,6 @@ declare global { interface Window { __scramjet$config: { prefix: string; - bareServer: string; codec: Codec scramjet: { config: string; @@ -19,7 +18,6 @@ declare global { self.__scramjet$config = { prefix: "/scramjet/", - bareServer: "/bare/", codec: self.__scramjet$codecs.plain, scramjet: { config: "/scramjet.config.js", diff --git a/src/worker/index.ts b/src/worker/index.ts index 65e64b2..c82a39b 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -1,7 +1,7 @@ importScripts("/scramjet.codecs.js"); importScripts("/scramjet.config.js"); importScripts("/scramjet.bundle.js"); -import { BareClient } from "@tomphttp/bare-client"; +import { BareClient } from "@mercuryworkshop/bare-mux"; declare global { interface Window { @@ -13,7 +13,7 @@ self.ScramjetServiceWorker = class ScramjetServiceWorker { client: typeof BareClient.prototype; constructor() { - this.client = new BareClient(location.origin + self.__scramjet$config.bareServer); + this.client = new BareClient(); } async fetch(event: FetchEvent) { diff --git a/static/index.html b/static/index.html index f152779..1c689b8 100644 --- a/static/index.html +++ b/static/index.html @@ -6,6 +6,8 @@ Document + + @@ -14,20 +16,26 @@