Skip to content

About

Development server for universal functions

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

13 watching

Forks

Helic Universal Development Server

Development server for local development of helix universal functions

Status

codecov GitHub Actions GitHub license GitHub issues semantic-release

Installation

$ npm install @adobe/helix-universal-devserver

Usage

// test/dev.js

import { DevelopmentServer } from '@adobe/helix-universal-devserver';
import { main } from '../src/index.js';

async function run() {
 const devServer = await new DevelopmentServer(main).init();
 await devServer.start();
}

run().then(process.stdout).catch(process.stderr);

Optional TCP host binding

Use the chainable withHost(host) method to select an explicit TCP hostname or IP address. For example, bind only to IPv4 loopback on an ephemeral port:

const devServer = await new DevelopmentServer(main)
  .withPort(0)
  .withHost('127.0.0.1')
  .init();
await devServer.start();

The assigned port is available as devServer.port. Omitting withHost preserves the existing port/callback listen behavior and defaults. An explicit host must be a non-empty, non-whitespace string; invalid values throw a TypeError before listening rather than falling back to an unspecified bind address. Normal startup errors and stop() behavior are unchanged.

The advertised localhost URL and x-forwarded-host header do not select the TCP bind address.

Test Helix Deploy Bundle

sometimes it is useful to test a bundled universal function directly, for example to verify that all imports are properly resolved. This can be achieved by setting the adapter, either to lambda or lambda.raw. the later bypasses loading of the secrets.

import { lambda } from '../../dist/helix-services/simple-function@2.4.44-bundle.cjs';

async function run() {
  const devServer = await new DevelopmentServer()
    .withHeader('x-forwarded-host', 'localhost:{port}')
    .withAdapter(lambda.raw) // use raw adapter and don't load secrets
    .init();
  await devServer.start();
}

Using development params with the server

Sometimes it might be useful to specify action params that would be provided during deployment but are not available during development. Those can be specified using the hlx configuration in your package.json. The development server will load parameters from:

  1. hlx.package.params-file and hlx.package.params
  2. hlx.params-file and hlx.params
  3. hlx.dev.params-file and hlx.dev.params (overrides the above)

Example using hlx (recommended):

{
  // ...
  "hlx": {
    "name": "my-action@${version}",
    "params-file": [
      "secrets.env"
    ],
    "params": {
      "MY_PARAM": "value"
    },
    "package": {
      "params-file": [
        "package-secrets.env"
      ],
      "params": {
        "PACKAGE_PARAM": "package-value"
      }
    },
    "dev": {
      "params-file": [
        ".dev-secrets.env"
      ],
      "params": {
        "DEV_PARAM": "dev-value"
      }
    }
  }
  // ...
}

Note: The deprecated wsk configuration key is still supported for backwards compatibility, but hlx is now the recommended standard. If both are present, hlx takes precedence. See the helix-deploy documentation for more details.

Development

Build

$ npm install

Test

$ npm test

Lint

$ npm run lint

About

Development server for universal functions

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

3 stars

Watchers

13 watching

Forks

Releases

Used by

Contributors

Languages