-
Notifications
You must be signed in to change notification settings - Fork 167
/
start.ts
45 lines (39 loc) · 1.75 KB
/
start.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { resolve } from 'https://deno.land/std@0.106.0/path/mod.ts'
import { existsDir } from '../shared/fs.ts'
import { Aleph } from '../server/aleph.ts'
import { serve } from '../server/mod.ts'
import { getFlag, parse, parsePortNumber } from './helper/flags.ts'
import log from '../shared/log.ts'
export const helpMessage = `
Usage:
aleph start <dir> [...options]
<dir> represents the directory of Aleph.js app,
if the <dir> is empty, the current directory will be used.
Options:
-p, --port <port> A port number to start the aleph.js app, default is 8080
--hostname <hostname> The address at which the server is to be started
--tls-cert <cert-file> The server certificate file
--tls-key <key-file> The server public key file
-L, --log-level <log-level> Set log level [possible values: debug, info]
-r, --reload Reload source code cache
-h, --help Prints help message
`
if (import.meta.main) {
const { args, options } = parse()
// check working dir
const workingDir = resolve(String(args[0] || '.'))
if (!await existsDir(workingDir)) {
log.fatal('No such directory:', workingDir)
}
const aleph = new Aleph(workingDir, 'production', Boolean(options.r || options.reload))
const port = parsePortNumber(getFlag(options, ['p', 'port'], '8080'))
const hostname = getFlag(options, ['hostname'])
const certFile = getFlag(options, ['tls-cert'])
const keyFile = getFlag(options, ['tls-key'])
if (keyFile !== undefined && certFile === undefined) {
log.fatal('missing `--tls-cert` option')
} else if (certFile !== undefined && keyFile === undefined) {
log.fatal('missing `--tls-key` option')
}
await serve({ aleph, port, hostname, certFile, keyFile })
}