fix: serve buttplug locally in dev instead of Docker
Add a minimal Node.js static server (serve.mjs) to the buttplug package that serves dist/ and wasm/ on port 8080 with correct MIME types. Update dev:buttplug to use it instead of docker compose, avoiding a full Rust/WASM Docker build on every dev start. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
],
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"build:wasm": "wasm-pack build --out-dir wasm --out-name index --target bundler --release"
|
||||
"build:wasm": "wasm-pack build --out-dir wasm --out-name index --target bundler --release",
|
||||
"serve": "node serve.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"eventemitter3": "^5.0.4",
|
||||
|
||||
39
packages/buttplug/serve.mjs
Normal file
39
packages/buttplug/serve.mjs
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
// Simple static server for local development — serves dist/ and wasm/ on port 8080
|
||||
import http from "http";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const PORT = process.env.PORT ?? 8080;
|
||||
|
||||
const MIME = {
|
||||
".js": "application/javascript",
|
||||
".wasm": "application/wasm",
|
||||
".ts": "text/plain",
|
||||
".d.ts": "text/plain",
|
||||
};
|
||||
|
||||
http
|
||||
.createServer((req, res) => {
|
||||
const filePath = path.join(__dirname, decodeURIComponent(req.url.split("?")[0]));
|
||||
const ext = path.extname(filePath);
|
||||
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) {
|
||||
res.writeHead(404);
|
||||
res.end("Not found");
|
||||
return;
|
||||
}
|
||||
res.writeHead(200, {
|
||||
"Content-Type": MIME[ext] ?? "application/octet-stream",
|
||||
"Cache-Control": "no-cache",
|
||||
"Cross-Origin-Resource-Policy": "cross-origin",
|
||||
});
|
||||
res.end(data);
|
||||
});
|
||||
})
|
||||
.listen(PORT, () => {
|
||||
console.log(`[buttplug] serving on http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user