MustafaMulla29/rp2040-bldc-motor-controller-new

73×72 mm 4-layer USB‑C PD (5/9/15/20 V) RP2040 controller PCB with protected power switching, MCT8329A sensorless BLDC three-phase MOSFET bridge, USB data/programming, onboard controls, and three motor outputs feeding a 2212 motor through rigid bullet adapters.

Version
0.3.100
License
unset
Stars
0

assembly/serve.ts

import { resolve, sep } from "node:path"
const root = import.meta.dir
const server = Bun.serve({
  hostname: "127.0.0.1", port: Number(process.env.ASSEMBLY_PREVIEW_PORT || 4185),
  async fetch(request) {
    const path = new URL(request.url).pathname
    const file = resolve(root, path === "/" ? "preview.html" : `.${decodeURIComponent(path)}`)
    if (!file.startsWith(root + sep) || !/\.(html|js|glb|json|md|jpg)$/.test(file)) return new Response("Not found", { status: 404 })
    const asset = Bun.file(file)
    if (!await asset.exists()) return new Response("Not found", { status: 404 })
    return new Response(asset, file.endsWith(".md") ? { headers: { "Content-Type": "text/plain; charset=utf-8" } } : undefined)
  },
})
console.log(`Assembly preview: ${server.url}`)