|
1 |
| -import { listenAndServe, path, walk } from './deps.ts' |
2 |
| -import { Request } from './server/api.ts' |
3 |
| -import { getContentType } from './server/mime.ts' |
4 |
| -import { createHtml } from './server/util.ts' |
| 1 | +import { path, walk } from './deps.ts' |
| 2 | +import { localProxy } from './server/localproxy.ts' |
5 | 3 | import { existsDirSync } from './shared/fs.ts'
|
6 | 4 | import type { LevelNames } from './shared/log.ts'
|
7 | 5 | import log from './shared/log.ts'
|
8 | 6 | import util from './shared/util.ts'
|
9 |
| -import type { ServerRequest } from './types.ts' |
10 | 7 | import { VERSION } from './version.ts'
|
11 | 8 |
|
12 | 9 | const commands = {
|
@@ -131,45 +128,8 @@ async function main() {
|
131 | 128 | log.debug('load env from', path.basename(p))
|
132 | 129 | }
|
133 | 130 |
|
134 |
| - // proxy https://deno.land/x/aleph for aleph.js dev |
135 |
| - const p = Deno.env.get('ALEPH_DEV_PORT') |
136 |
| - if (p && !/^\d+$/.test(p)) { |
137 |
| - log.fatal('invalid ALEPH_DEV_PORT:', p) |
138 |
| - } |
139 |
| - if (p) { |
140 |
| - const cwd = Deno.cwd() |
141 |
| - const port = parseInt(p) |
142 |
| - listenAndServe({ port }, async (req: ServerRequest) => { |
143 |
| - const url = new URL('http://localhost' + req.url) |
144 |
| - const resp = new Request(req, util.cleanPath(url.pathname), {}, url.searchParams) |
145 |
| - const filepath = path.join(cwd, url.pathname) |
146 |
| - try { |
147 |
| - const info = await Deno.lstat(filepath) |
148 |
| - if (info.isDirectory) { |
149 |
| - const r = Deno.readDir(filepath) |
150 |
| - const items: string[] = [] |
151 |
| - for await (const item of r) { |
152 |
| - if (!item.name.startsWith('.')) { |
153 |
| - items.push(`<li><a href='${path.join(url.pathname, encodeURI(item.name))}'>${item.name}${item.isDirectory ? '/' : ''}<a></li>`) |
154 |
| - } |
155 |
| - } |
156 |
| - resp.send(createHtml({ |
157 |
| - head: [`<title>aleph.js/</title>`], |
158 |
| - body: `<h1> aleph.js/</h1><ul>${Array.from(items).join('')}</ul>` |
159 |
| - }), 'text/html') |
160 |
| - return |
161 |
| - } |
162 |
| - resp.send(await Deno.readFile(filepath), getContentType(filepath)) |
163 |
| - } catch (err) { |
164 |
| - if (err instanceof Deno.errors.NotFound) { |
165 |
| - resp.status(404).send('file not found') |
166 |
| - return |
167 |
| - } |
168 |
| - resp.status(500).send(err.message) |
169 |
| - } |
170 |
| - }) |
171 |
| - log.info(`Proxy https://deno.land/x/aleph on http://localhost:${port}`) |
172 |
| - } |
| 131 | + // proxy https://deno.land/x/aleph on localhost |
| 132 | + localProxy() |
173 | 133 |
|
174 | 134 | const { default: cmd } = await import(`./cli/${command}.ts`)
|
175 | 135 | switch (command) {
|
|
0 commit comments