Skip to content

Commit

Permalink
feat: allow certificate to be supplied to serve (#7)
Browse files Browse the repository at this point in the history
* feat: allow certificate to be supplied to `serve`

* feat: add support for server certificate

* refactor: remove `--origin-protocol` flag
  • Loading branch information
eduardoboucas authored May 3, 2022
1 parent 3ba4482 commit 51eabf7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface PrepareServerOptions {
const prepareServer = ({
deno,
distDirectory,
flags,
flags: denoFlags,
formatExportTypeError,
formatImportError,
port,
Expand Down Expand Up @@ -56,7 +56,9 @@ const prepareServer = ({
// no-op
}

await deno.runInBackground(['run', ...flags, stage2Path, port.toString()], true, processRef)
const bootstrapFlags = ['--port', port.toString()]

await deno.runInBackground(['run', ...denoFlags, stage2Path, ...bootstrapFlags], true, processRef)

const success = await waitForServer(port, processRef.ps)

Expand All @@ -70,6 +72,7 @@ const prepareServer = ({
}

interface ServeOptions {
certificatePath?: string
debug?: boolean
distImportMapPath?: string
importMaps?: ImportMapFile[]
Expand All @@ -81,6 +84,7 @@ interface ServeOptions {
}

const serve = async ({
certificatePath,
debug,
distImportMapPath,
formatExportTypeError,
Expand Down Expand Up @@ -108,13 +112,24 @@ const serve = async ({
const importMap = new ImportMap(importMaps)
const flags = ['--allow-all', '--unstable', `--import-map=${importMap.toDataURL()}`]

if (certificatePath) {
flags.push(`--cert=${certificatePath}`)
}

if (debug) {
flags.push('--log-level=debug')
} else {
flags.push('--quiet')
}

const server = await prepareServer({ deno, distDirectory, flags, formatExportTypeError, formatImportError, port })
const server = await prepareServer({
deno,
distDirectory,
flags,
formatExportTypeError,
formatImportError,
port,
})

if (distImportMapPath) {
await importMap.writeToFile(distImportMapPath)
Expand Down

0 comments on commit 51eabf7

Please sign in to comment.