diff --git a/frontend.js b/frontend.js index 6c35c1a..7825c7e 100644 --- a/frontend.js +++ b/frontend.js @@ -15,7 +15,6 @@ export class Frontend { this.apiBaseUrl = apiBaseUrl this.appBaseUrl = appBaseUrl this.files = {} - this.tasks = [] } repoUrl(user, repo) { @@ -92,28 +91,21 @@ export class Frontend { const resp = await fetch(url) this.checkOk(resp) const contents = await resp.json() - for (const item of contents) { - if (item.type === 'dir') { - this.tasks.push(this.loadRepo(user, repo, { - ...opts, - srcPath: [...srcPath, item.name], - destPath: [...destPath, item.name], - })) - } else { - this.tasks.push(this.loadFile( - user, - repo, - item.last_commit_sha, - [...srcPath, item.name], - [...destPath, item.name], - )) - } - } - let prevCount = 0 - while (this.tasks.count > prevCount) { - prevCount = this.tasks.length - await Promise.all(this.tasks) - } + await Promise.all(contents.map(item => ( + item.type === 'dir' ? + this.loadRepo(user, repo, { + ...opts, + srcPath: [...srcPath, item.name], + destPath: [...destPath, item.name], + }) : + this.loadFile( + user, + repo, + item.last_commit_sha, + [...srcPath, item.name], + [...destPath, item.name], + ) + ))) } async serve(event) { diff --git a/server.js b/server.js index 9736982..b58593a 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,5 @@ -import { Auth } from "./auth" -import { Frontend } from "./frontend" +//import { Auth } from "./auth" +//import { Frontend } from "./frontend" export class Server { async getEnv(variables) { @@ -37,44 +37,46 @@ export class Server { } async init() { + if (this.port === undefined) { + await this.configure() + } this.auth = new Auth() this.frontend = new Frontend({ appBaseUrl: this.giteaAppBaseUrl, apiBaseUrl: this.giteaApiBaseUrl, }) - const promises = [] - const repos = [ - 'loader', - 'editor', - 'forms', - 'menu', - 'settings', - 'dialog', - 'storage', - 'editor-lib-codemirror', - ] - for (const repo of repos) { - promises.push(server.frontend.loadRepo( + await Promise.all([ + ...([ + 'loader', + 'editor', + 'forms', + 'menu', + 'settings', + 'dialog', + 'storage', + 'editor-lib-codemirror', + ].map(repo => ( + server.frontend.loadRepo( + 'macchiato', + repo, + {srcPath: [], destPath: [repo]} + ) + ))), + server.frontend.loadRepo( 'macchiato', - repo, - {srcPath: [], destPath: [repo]} - )) - } - promises.push(server.frontend.loadRepo( - 'macchiato', - 'pages', - {srcPath: [], destPath: []} - )) - promises.push(server.frontend.loadRepo( - 'macchiato', - 'server', - { - srcPath: [], - destPath: ['server'], - ref: 'shared-server' - } - )) - await Promise.all(promises) + 'pages', + {srcPath: [], destPath: []} + ), + server.frontend.loadRepo( + 'macchiato', + 'server', + { + srcPath: [], + destPath: ['server'], + ref: 'shared-server' + } + ), + ]) this.frontend.files['/app.js'] = ( this.frontend.files['/server/app.js'] ) @@ -110,8 +112,9 @@ export class Server { } async serve() { - await this.configure() - await this.init() + if (!this.server) { + await this.init() + } this.server = Deno.listen({ port: this.port, }) @@ -119,10 +122,4 @@ export class Server { this.serveConn(conn) } } - - async run() { - await this.configure() - await this.init() - await this.serve() - } } \ No newline at end of file