Convert to bearmetal router, updated sockpuppet
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { SockpuppetPlus } from "@cgg/sockpuppet";
|
||||
import { Sockpuppet } from "@bearmetal/sockpuppet";
|
||||
import { serveDir, serveFile } from "@std/http/file-server";
|
||||
import { BearMetalStore } from "@bearmetal/store";
|
||||
import { ensureDir, ensureFile, exists } from "@std/fs";
|
||||
import { Router } from "./router.ts";
|
||||
import { Router } from "@bearmetal/router";
|
||||
import { getPackVersion } from "./util/packVersion.ts";
|
||||
import { createTagRoutes } from "./tags/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 sockpuppet = new SockpuppetPlus();
|
||||
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);
|
||||
});
|
||||
|
||||
const sockpuppet = new Sockpuppet();
|
||||
// sockpuppet.addHandler((req: Request) => {
|
||||
// const method = req.method;
|
||||
// if (method === "OPTIONS") {
|
||||
// return new Response(null, {
|
||||
// status: 200,
|
||||
// headers: {
|
||||
// "Access-Control-Allow-Origin": "*",
|
||||
// "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
||||
// },
|
||||
// });
|
||||
// }
|
||||
// const url = new URL(req.url);
|
||||
// if (!url.pathname.startsWith("/images")) return;
|
||||
|
||||
// return serveFile(req, url.searchParams.get("location") as string);
|
||||
// });
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.route("/images").get((req,ctx) => serveFile(req,ctx.url.searchParams.get("location") as string));
|
||||
|
||||
router.route("/api/dir")
|
||||
.get(async () => {
|
||||
console.log("hitting dir");
|
||||
using store = new BearMetalStore();
|
||||
const mcPath = store.get("mcPath") as string;
|
||||
if (mcPath) {
|
||||
@@ -257,15 +247,19 @@ router.route("/api/stream/test")
|
||||
});
|
||||
})
|
||||
|
||||
sockpuppet.addHandler((req: Request) => {
|
||||
if (new URL(req.url).pathname.startsWith("/api")) return;
|
||||
// sockpuppet.addHandler((req: Request) => {
|
||||
// if (new URL(req.url).pathname.startsWith("/api")) return;
|
||||
|
||||
return serveDir(req, {
|
||||
fsRoot: installPath + "dist",
|
||||
});
|
||||
});
|
||||
// return serveDir(req, {
|
||||
// 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) {
|
||||
const realWorldPath = store.get("world");
|
||||
|
@@ -1,12 +1,12 @@
|
||||
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 { versionCompat } from "../util/versionCompat.ts";
|
||||
import { readBlocks, readItems } from "./readers.ts";
|
||||
|
||||
export const createResourcesRoutes = (router: Router) => {
|
||||
router.route("/api/resources/:path*")
|
||||
.get(async (req, ctx) => {
|
||||
.get(async (_req, ctx) => {
|
||||
const path = ctx.params.path;
|
||||
if (!path) {
|
||||
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 { getPackVersion } from "../util/packVersion.ts";
|
||||
import type { Router } from "../router.ts";
|
||||
import type { Router } from "@bearmetal/router";
|
||||
import { getTagDir } from "./getTagDir.ts";
|
||||
import { ensureDir } from "@std/fs/ensure-dir";
|
||||
import { ensureFile } from "@std/fs/ensure-file";
|
||||
|
Reference in New Issue
Block a user