Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 216b39d

Browse files
committed
refactor: imporove console output
1 parent b3fc54e commit 216b39d

File tree

3 files changed

+40
-42
lines changed

3 files changed

+40
-42
lines changed

server/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class Application implements ServerApplication {
137137
const { init } = await import(`../framework/${framework}/init.ts`)
138138
await init(this)
139139

140-
log.info('Building...')
140+
log.info('Compiling...')
141141

142142
// pre-compile framework modules
143143
await this.compile(`${alephPkgUri}/framework/${framework}/bootstrap.ts`)

server/localproxy.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,47 @@ import { getContentType } from './mime.ts'
66

77
/** proxy https://deno.land/x/aleph on localhost */
88
export async function localProxy() {
9-
const p = Deno.env.get('ALEPH_DEV_PORT')
10-
if (!p) {
11-
return
12-
}
9+
const p = Deno.env.get('ALEPH_DEV_PORT')
10+
if (!p) {
11+
return
12+
}
1313

14-
if (!/^\d+$/.test(p)) {
15-
log.fatal('invalid ALEPH_DEV_PORT:', p)
16-
}
14+
if (!/^\d+$/.test(p)) {
15+
log.fatal('invalid ALEPH_DEV_PORT:', p)
16+
}
1717

18-
const cwd = Deno.cwd()
19-
const port = parseInt(p)
20-
const s = serve({ port })
18+
const cwd = Deno.cwd()
19+
const port = parseInt(p)
20+
const s = serve({ port })
2121

22-
log.info(`Proxy https://deno.land/x/aleph on http://localhost:${port}`)
23-
for await (const r of s) {
24-
const url = new URL('http://localhost' + r.url)
25-
const resp = new Request(r, {}, url.searchParams)
26-
const filepath = path.join(cwd, url.pathname)
27-
try {
28-
const info = await Deno.lstat(filepath)
29-
if (info.isDirectory) {
30-
const r = Deno.readDir(filepath)
31-
const items: string[] = []
32-
for await (const item of r) {
33-
if (!item.name.startsWith('.')) {
34-
items.push(`<li><a href='${path.join(url.pathname, encodeURI(item.name))}'>${item.name}${item.isDirectory ? '/' : ''}<a></li>`)
35-
}
36-
}
37-
resp.send(createHtml({
38-
head: [`<title>aleph.js/</title>`],
39-
body: `<h1>&nbsp;aleph.js/</h1><ul>${Array.from(items).join('')}</ul>`
40-
}), 'text/html')
41-
return
42-
}
43-
resp.send(await Deno.readFile(filepath), getContentType(filepath))
44-
} catch (err) {
45-
if (err instanceof Deno.errors.NotFound) {
46-
resp.status(404).send('file not found')
47-
return
48-
}
49-
resp.status(500).send(err.message)
22+
log.debug(`Proxy https://deno.land/x/aleph on http://localhost:${port}`)
23+
for await (const r of s) {
24+
const url = new URL('http://localhost' + r.url)
25+
const resp = new Request(r, {}, url.searchParams)
26+
const filepath = path.join(cwd, url.pathname)
27+
try {
28+
const info = await Deno.lstat(filepath)
29+
if (info.isDirectory) {
30+
const r = Deno.readDir(filepath)
31+
const items: string[] = []
32+
for await (const item of r) {
33+
if (!item.name.startsWith('.')) {
34+
items.push(`<li><a href='${path.join(url.pathname, encodeURI(item.name))}'>${item.name}${item.isDirectory ? '/' : ''}<a></li>`)
35+
}
5036
}
37+
resp.send(createHtml({
38+
head: [`<title>aleph.js/</title>`],
39+
body: `<h1>&nbsp;aleph.js/</h1><ul>${Array.from(items).join('')}</ul>`
40+
}), 'text/html')
41+
return
42+
}
43+
resp.send(await Deno.readFile(filepath), getContentType(filepath))
44+
} catch (err) {
45+
if (err instanceof Deno.errors.NotFound) {
46+
resp.status(404).send('file not found')
47+
return
48+
}
49+
resp.status(500).send(err.message)
5150
}
51+
}
5252
}

server/server.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ export type ServeOptions = {
196196

197197
/** Create a standard Aleph server. */
198198
export async function serve({ app, port, hostname, certFile, keyFile }: ServeOptions) {
199-
const server = new Server(app)
200-
await app.ready
201-
202199
while (true) {
203200
try {
204201
let s: AsyncIterable<ServerRequest>
@@ -207,6 +204,7 @@ export async function serve({ app, port, hostname, certFile, keyFile }: ServeOpt
207204
} else {
208205
s = stdServe({ port, hostname })
209206
}
207+
const server = new Server(app)
210208
log.info(`Server ready on http://${hostname || 'localhost'}:${port}${app.config.baseUrl}`)
211209
for await (const r of s) {
212210
server.handle(r)

0 commit comments

Comments
 (0)