Convert to bearmetal router, updated sockpuppet
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
},
|
},
|
||||||
"imports": {
|
"imports": {
|
||||||
"@babel/plugin-transform-react-jsx-development": "npm:@babel/plugin-transform-react-jsx-development@^7.25.7",
|
"@babel/plugin-transform-react-jsx-development": "npm:@babel/plugin-transform-react-jsx-development@^7.25.7",
|
||||||
|
"@bearmetal/router": "jsr:@bearmetal/router@^0.1.1",
|
||||||
|
"@bearmetal/sockpuppet": "jsr:@bearmetal/sockpuppet@^1.0.0",
|
||||||
"@bearmetal/store": "jsr:@bearmetal/store@^0.0.5",
|
"@bearmetal/store": "jsr:@bearmetal/store@^0.0.5",
|
||||||
"@cgg/sockpuppet": "../sockpuppet.ts/server/mod.ts",
|
"@cgg/sockpuppet": "../sockpuppet.ts/server/mod.ts",
|
||||||
"@cgg/sockpuppet/client": "../sockpuppet.ts/client/mod.ts",
|
"@cgg/sockpuppet/client": "../sockpuppet.ts/client/mod.ts",
|
||||||
|
10
deno.lock
generated
10
deno.lock
generated
@@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
"version": "4",
|
"version": "4",
|
||||||
"specifiers": {
|
"specifiers": {
|
||||||
|
"jsr:@bearmetal/router@~0.1.1": "0.1.1",
|
||||||
|
"jsr:@bearmetal/sockpuppet@1": "1.0.0",
|
||||||
"jsr:@bearmetal/store@^0.0.5": "0.0.5",
|
"jsr:@bearmetal/store@^0.0.5": "0.0.5",
|
||||||
"jsr:@denosaurs/plug@1.0.5": "1.0.5",
|
"jsr:@denosaurs/plug@1.0.5": "1.0.5",
|
||||||
"jsr:@gfx/canvas@~0.5.8": "0.5.8",
|
"jsr:@gfx/canvas@~0.5.8": "0.5.8",
|
||||||
@@ -43,6 +45,12 @@
|
|||||||
"npm:vite@^5.4.8": "5.4.9"
|
"npm:vite@^5.4.8": "5.4.9"
|
||||||
},
|
},
|
||||||
"jsr": {
|
"jsr": {
|
||||||
|
"@bearmetal/router@0.1.1": {
|
||||||
|
"integrity": "cd526ac6b4a6426ac171f3868f83ec1727ebf2de21aad4e1f128c2605345f19d"
|
||||||
|
},
|
||||||
|
"@bearmetal/sockpuppet@1.0.0": {
|
||||||
|
"integrity": "e6dc133b2a5c9e7f1fb99309f592c24b0b8ffd4fc43ee3d61313f5c517ddfb8c"
|
||||||
|
},
|
||||||
"@bearmetal/store@0.0.5": {
|
"@bearmetal/store@0.0.5": {
|
||||||
"integrity": "d17da24c91bcc05707deb8a55017ebdf5d8eebd2f6293dcb2bbfac57e4e3b395",
|
"integrity": "d17da24c91bcc05707deb8a55017ebdf5d8eebd2f6293dcb2bbfac57e4e3b395",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
@@ -1488,6 +1496,8 @@
|
|||||||
},
|
},
|
||||||
"workspace": {
|
"workspace": {
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
"jsr:@bearmetal/router@~0.1.1",
|
||||||
|
"jsr:@bearmetal/sockpuppet@1",
|
||||||
"jsr:@bearmetal/store@^0.0.5",
|
"jsr:@bearmetal/store@^0.0.5",
|
||||||
"jsr:@gfx/canvas@~0.5.8",
|
"jsr:@gfx/canvas@~0.5.8",
|
||||||
"jsr:@std/encoding@^1.0.5",
|
"jsr:@std/encoding@^1.0.5",
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import { SockpuppetPlus } from "@cgg/sockpuppet";
|
import { Sockpuppet } from "@bearmetal/sockpuppet";
|
||||||
import { serveDir, serveFile } from "@std/http/file-server";
|
import { serveDir, serveFile } from "@std/http/file-server";
|
||||||
import { BearMetalStore } from "@bearmetal/store";
|
import { BearMetalStore } from "@bearmetal/store";
|
||||||
import { ensureDir, ensureFile, exists } from "@std/fs";
|
import { ensureDir, ensureFile, exists } from "@std/fs";
|
||||||
import { Router } from "./router.ts";
|
import { Router } from "@bearmetal/router";
|
||||||
import { getPackVersion } from "./util/packVersion.ts";
|
import { getPackVersion } from "./util/packVersion.ts";
|
||||||
import { createTagRoutes } from "./tags/routes.ts";
|
import { createTagRoutes } from "./tags/routes.ts";
|
||||||
import { createResourcesRoutes } from "./resources/routes.ts";
|
import { createResourcesRoutes } from "./resources/routes.ts";
|
||||||
@@ -11,31 +11,21 @@ import { unzipResources } from "./resources/unzip.ts";
|
|||||||
|
|
||||||
const installPath = Deno.env.get("BMP_INSTALL_DIR") || "./";
|
const installPath = Deno.env.get("BMP_INSTALL_DIR") || "./";
|
||||||
|
|
||||||
const sockpuppet = new SockpuppetPlus();
|
const sockpuppet = new Sockpuppet();
|
||||||
sockpuppet.addHandler((req: Request) => {
|
|
||||||
const url = new URL(req.url);
|
|
||||||
if (!url.pathname.startsWith("/images")) return;
|
|
||||||
|
|
||||||
return serveFile(req, url.searchParams.get("location") as string);
|
|
||||||
});
|
|
||||||
|
|
||||||
// sockpuppet.addHandler((req: Request) => {
|
// sockpuppet.addHandler((req: Request) => {
|
||||||
// const method = req.method;
|
// const url = new URL(req.url);
|
||||||
// if (method === "OPTIONS") {
|
// if (!url.pathname.startsWith("/images")) return;
|
||||||
// return new Response(null, {
|
|
||||||
// status: 200,
|
// return serveFile(req, url.searchParams.get("location") as string);
|
||||||
// headers: {
|
|
||||||
// "Access-Control-Allow-Origin": "*",
|
|
||||||
// "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
|
router.route("/images").get((req,ctx) => serveFile(req,ctx.url.searchParams.get("location") as string));
|
||||||
|
|
||||||
router.route("/api/dir")
|
router.route("/api/dir")
|
||||||
.get(async () => {
|
.get(async () => {
|
||||||
|
console.log("hitting dir");
|
||||||
using store = new BearMetalStore();
|
using store = new BearMetalStore();
|
||||||
const mcPath = store.get("mcPath") as string;
|
const mcPath = store.get("mcPath") as string;
|
||||||
if (mcPath) {
|
if (mcPath) {
|
||||||
@@ -257,15 +247,19 @@ router.route("/api/stream/test")
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
sockpuppet.addHandler((req: Request) => {
|
// sockpuppet.addHandler((req: Request) => {
|
||||||
if (new URL(req.url).pathname.startsWith("/api")) return;
|
// if (new URL(req.url).pathname.startsWith("/api")) return;
|
||||||
|
|
||||||
return serveDir(req, {
|
// return serveDir(req, {
|
||||||
fsRoot: installPath + "dist",
|
// fsRoot: installPath + "dist",
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
sockpuppet.addHandler(router.handle);
|
router.route("/").get((req) => serveDir(req, {fsRoot:installPath + "dist"}));
|
||||||
|
|
||||||
|
router.route("/ws").get(sockpuppet.handler)
|
||||||
|
|
||||||
|
Deno.serve(router.handle);
|
||||||
|
|
||||||
async function createPack(store: BearMetalStore, packName: string) {
|
async function createPack(store: BearMetalStore, packName: string) {
|
||||||
const realWorldPath = store.get("world");
|
const realWorldPath = store.get("world");
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
import { ensureDir } from "@std/fs/ensure-dir";
|
import { ensureDir } from "@std/fs/ensure-dir";
|
||||||
import type { Router } from "../router.ts";
|
import type { Router } from "@bearmetal/router";
|
||||||
import { readDirDirs } from "../util/readDir.ts";
|
import { readDirDirs } from "../util/readDir.ts";
|
||||||
import { versionCompat } from "../util/versionCompat.ts";
|
import { versionCompat } from "../util/versionCompat.ts";
|
||||||
import { readBlocks, readItems } from "./readers.ts";
|
import { readBlocks, readItems } from "./readers.ts";
|
||||||
|
|
||||||
export const createResourcesRoutes = (router: Router) => {
|
export const createResourcesRoutes = (router: Router) => {
|
||||||
router.route("/api/resources/:path*")
|
router.route("/api/resources/:path*")
|
||||||
.get(async (req, ctx) => {
|
.get(async (_req, ctx) => {
|
||||||
const path = ctx.params.path;
|
const path = ctx.params.path;
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return new Response("no path provided", { status: 400 });
|
return new Response("no path provided", { status: 400 });
|
||||||
@@ -99,5 +99,6 @@ export const createResourcesRoutes = (router: Router) => {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new Response("no path provided", { status: 400 });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { BearMetalStore } from "@bearmetal/store";
|
import { BearMetalStore } from "@bearmetal/store";
|
||||||
import { getPackVersion } from "../util/packVersion.ts";
|
import { getPackVersion } from "../util/packVersion.ts";
|
||||||
import type { Router } from "../router.ts";
|
import type { Router } from "@bearmetal/router";
|
||||||
import { getTagDir } from "./getTagDir.ts";
|
import { getTagDir } from "./getTagDir.ts";
|
||||||
import { ensureDir } from "@std/fs/ensure-dir";
|
import { ensureDir } from "@std/fs/ensure-dir";
|
||||||
import { ensureFile } from "@std/fs/ensure-file";
|
import { ensureFile } from "@std/fs/ensure-file";
|
||||||
|
Reference in New Issue
Block a user