Skip to content

Serve Configuration ​

The serve option in xbuild.config.ts launches an HTTP or HTTPS server that serves the build output.

Enable it from the command line without touching the config:

bash
xbuild -s
# or
xbuild --serve

This is equivalent to setting serve: { active: true }.

Example ​

ts
const config = {
    serve: {
        active: true,
        port: 8080,
        host: 'localhost',
        keyfile: '/path/to/ssl/keyfile.pem',
        certfile: '/path/to/ssl/certfile.pem',
        onStart: () => {
            console.log('Server started');
        },
        onRequest: (req, res, next) => {
            console.log('Incoming request');
            next();
        }
    }
};

Properties ​

PropertyTypeDescription
activebooleanEnable the server. Equivalent to -s / --serve on the CLI.
portnumberPort to listen on.
hoststringHostname, e.g. "localhost" or "0.0.0.0".
keyfilestring?Path to the SSL key file (enables HTTPS).
certfilestring?Path to the SSL certificate file (enables HTTPS).
onRequest(req, res, next) => voidCustom handler run on every request. Call next() to continue.
onStart() => voidCallback run once the server starts.

See also ​

Released under the Mozilla Public License 2.0