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(); for await (const dirEntry of Deno.readDir(Deno.cwd())) { if (!(dirEntry.isDirectory && dirEntry.name.includes('-service'))) continue; 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 port = await Deno.readTextFile(portfile); const p = new Deno.Command(Deno.execPath(), { args: [ 'run', ...perms, filename, port ] }).spawn() const prefix = Deno.readTextFileSync(prefixfile); const routes = new Router() .all(`/${prefix}/(.*)`, proxy((ctx: Context) => `http://localhost:${port}${ctx.request.url.pathname}`, {})) app.use(routes.allowedMethods()); app.use(routes.routes()); } app.listen({ port: 3000 })