Skip to main content

Setting options

bud.serve also supports an options object for more specific configurations:

bud.serve({
host: `dev.example.test`,
})

You can also pass options as a second parameter to bud.serve. This can be convenient when you want to specify some options but want to keep the simple configuration syntax for the rest:

bud.serve(`https://dev.example.test`, {
cert: bud.path('example.test.crt'),
key: bud.path('example.test.key'),
})

All options

PropertyTypeDescription
hoststringURL['hostname']
portnumberURL['port']
urlURLURL
sslbooleanIs the server https enabled?
certstringThe ssl certificate path
keystringThe ssl key path
optionsHttps.ServerOptionsDirect access to the server options

Setting the origin

You can use host and port to set the server origin:

bud.serve({
host: 'dev.example.test',
port: 3000,
})

Alternatively, you can set the origin with a using the url property:

bud.serve({
url: new URL('http://dev.example.test:3000'),
})

SSL

Use the ssl option to indicate that the server should be https enabled. This requires that cert and key options to be set as well.

bud.serve({
ssl: true,
host: 'dev.example.test',
cert: bud.path('example.test.crt'),
key: bud.path('example.test.key'),
})

Note in the example above that the cert and key are paths. This is different than the Node API, which both expect a Buffer.

You don't need to include ssl if you are using the url property. It will be inferred from the URL's protocol.

Using the Node API

If you want to use the node API more directly you can use the options property:

const cert = await bud.fs.read('example.test.crt')
const key = await bud.fs.read('example.test.key')

bud.serve(`https://dev.example.test`, {
options: {cert, key},
})