Honestly way too much went into this single commit. I am so sorry future me
This commit is contained in:
30
startDev.ts
30
startDev.ts
@@ -1,38 +1,38 @@
|
||||
import { copy } from "https://deno.land/std@0.104.0/io/util.ts";
|
||||
import { proxy } from "https://deno.land/x/oak_http_proxy@2.1.0/mod.ts";
|
||||
import { fileExists } from "./lib/fileExists.ts";
|
||||
import { Application, Context, Router } from "oak";
|
||||
import { path } from "https://deno.land/x/compress@v0.4.1/deps.ts";
|
||||
const app = new Application();
|
||||
|
||||
|
||||
let port = 3001;
|
||||
for await (const dirEntry of Deno.readDir(Deno.cwd())) {
|
||||
if (!(dirEntry.isDirectory && dirEntry.name.includes('-service'))) continue;
|
||||
const filename = dirEntry.name + '/index.ts';
|
||||
const filename = dirEntry.name + '/main.ts';
|
||||
const permfile = dirEntry.name + '/perms';
|
||||
const prefixfile = dirEntry.name + '/prefix';
|
||||
const portfile = dirEntry.name + '/port';
|
||||
if (!(await fileExists(filename))) continue;
|
||||
if (!(await fileExists(prefixfile))) continue;
|
||||
|
||||
const perms = (await fileExists(permfile)) ? await Deno.readTextFileSync(permfile).split('\n') : []
|
||||
// successful, file or directory must exist
|
||||
const p = Deno.run({
|
||||
cmd: ['deno', 'run', ...perms, '--watch', filename, port.toString()],
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
})
|
||||
const port = await Deno.readTextFile(portfile);
|
||||
const p = new Deno.Command(Deno.execPath(), {
|
||||
args: [
|
||||
'run',
|
||||
...perms,
|
||||
filename,
|
||||
port
|
||||
]
|
||||
}).spawn()
|
||||
|
||||
const prefix = Deno.readTextFileSync(prefixfile);
|
||||
const fixedPort = port;
|
||||
const routes = new Router()
|
||||
.all(`/${prefix}/(.*)`, proxy((ctx: Context) => `http://localhost:${fixedPort}${ctx.request.url.pathname}`, {}))
|
||||
app.use(routes.routes());
|
||||
.all(`/${prefix}/(.*)`, proxy((ctx: Context) => `http://localhost:${port}${ctx.request.url.pathname}`, {}))
|
||||
|
||||
app.use(routes.allowedMethods());
|
||||
app.use(routes.routes());
|
||||
|
||||
port++;
|
||||
|
||||
copy(p.stdout, Deno.stdout);
|
||||
copy(p.stderr, Deno.stderr);
|
||||
}
|
||||
|
||||
app.listen({
|
||||
|
Reference in New Issue
Block a user