@@ -6,47 +6,47 @@ import { getContentType } from './mime.ts'
6
6
7
7
/** proxy https://deno.land/x/aleph on localhost */
8
8
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
+ }
13
13
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
+ }
17
17
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 } )
21
21
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> 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
+ }
50
36
}
37
+ resp . send ( createHtml ( {
38
+ head : [ `<title>aleph.js/</title>` ] ,
39
+ body : `<h1> 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 )
51
50
}
51
+ }
52
52
}
0 commit comments