-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.ts
31 lines (25 loc) · 862 Bytes
/
serve.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2023-2024 the Sequoia authors. All rights reserved. MIT license.
import { Application } from './mod.ts'
import { Router } from './router.ts'
import { parseArgs, stdPath } from './deps.ts'
const pathArg = Deno.args[0]
const flags = parseArgs(Deno.args, {
string: ['hostname', 'port'],
})
const HOSTNAME = flags.hostname ?? '0.0.0.0'
const PORT = flags.port ? +flags.port : 8080
if (!pathArg) {
throw new Deno.errors.NotFound(
'Please specify a path to serve. Example: deno run -A serve.ts build/static',
)
}
const PATH = stdPath.normalize(pathArg)
const app = new Application()
app.useRouter('/', new Router().static('/', PATH))
app.listen(
{ hostname: HOSTNAME, port: PORT },
() => {
console.log(`Sequoia server is running at http://${HOSTNAME}:${PORT}`)
console.log(`Now serving ${PATH}`)
},
)