Listen on 0.0.0.0
This commit is contained in:
parent
175ee5018f
commit
a8a6d544e3
|
@ -1,24 +1,31 @@
|
||||||
|
#!/usr/bin/env -S deno run --allow-run --allow-net
|
||||||
// Automated bundle server
|
// Automated bundle server
|
||||||
|
|
||||||
import { serve } from "https://deno.land/std/http/server.ts";
|
import { serve } from "https://deno.land/std/http/server.ts";
|
||||||
import { bool } from "https://code.thunderk.net/typescript/functional/raw/1.0.0/all.ts";
|
import { bool } from "https://code.thunderk.net/typescript/functional/raw/1.0.0/all.ts";
|
||||||
|
|
||||||
const server = serve({ port: 8000 });
|
async function serveBundles() {
|
||||||
for await (const req of server) {
|
const listen = { hostname: "0.0.0.0", port: 8000 };
|
||||||
const params = req.url.split("/").filter(bool);
|
const server = serve(listen);
|
||||||
const lib = params[0] || "all";
|
console.log(`Serving bundles on ${listen.hostname}:${listen.port} ...`);
|
||||||
const version = params[1] || "master";
|
for await (const req of server) {
|
||||||
const file = params.length > 2 ? params.slice(2).join("/") : "all";
|
const params = req.url.split("/").filter(bool);
|
||||||
const path =
|
const lib = params[0] || "all";
|
||||||
`https://code.thunderk.net/typescript/${lib}/raw/${version}/${file}.ts`;
|
const version = params[1] || "master";
|
||||||
|
const file = params.length > 2 ? params.slice(2).join("/") : "all";
|
||||||
|
const path =
|
||||||
|
`https://code.thunderk.net/typescript/${lib}/raw/${version}/${file}.ts`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const process = Deno.run({
|
const process = Deno.run({
|
||||||
cmd: ["deno", "bundle", path],
|
cmd: ["deno", "bundle", path],
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
req.respond({ body: await process.output() });
|
req.respond({ body: await process.output() });
|
||||||
} catch {
|
} catch {
|
||||||
req.respond({ body: `console.error("Failed to bundle ${path}");` });
|
req.respond({ body: `console.error("Failed to bundle ${path}");` });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await serveBundles();
|
||||||
|
|
Loading…
Reference in New Issue