npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@equinor/fusion-framework-module-service-discovery

v8.0.3

Published

This module is for resolving service endpoints from a service discovery service.

Downloads

8,756

Readme

Fusion Service Discovery Module

This module is for resolving service endpoints from a service discovery service.

[!WARNING] This module requires @equinor/fusion-framework-module-http to to create http clients, so the module must be enabled in runtime.

Configure

This module requires a http client to be configured. The http client should be configured with a key that is used to resolve the service endpoints.

[!NOTE] The Service Discovery Module inherits configuration when used in sub-modules (ex. Application), which means that the http client should be configured in the root module (ex Portal).

Skip this step if the http client is already configured.

import { ModulesConfigurator } from '@equinor/fusion-framework-module';
const configurator = new ModulesConfigurator();
configurator.addConfig(
    configureHttpClient(
      'service_discovery', 
      { /* http config */ }
    )
);

Simple Configuration

In the simplest form, the service discovery module can be enabled with the following code:

import enableServiceDiscovery from '@equinor/fusion-framework-service-discovery';

// the module will setup the service discovery client with default configuration
// Assumes that http client is configured with key 'service_discovery'
enableServiceDiscovery(configurator);

Override default http client key

If the http client is configured with a different key, the key can be specified as follows:

enableServiceDiscovery(
  configurator, 
  async(builder: ServiceDiscoveryConfigurator) => {
    builder.configureServiceDiscoveryClientByClientKey(
      // assume that http client is configured with this key
      'service_discovery_custom', 
      // optional endpoint path
      '/custom/services' 
    );
});

Advanced Configuration

Override default http client

If a custom http client is required, the client can be configured as follows:

enableServiceDiscovery(
  configurator, 
  async(builder: ServiceDiscoveryConfigurator) => {
    builder.configureServiceDiscoveryClient(
      // configurator callback
      async (args: ConfigBuilderCallbackArgs) => {
        // using build environment to create a http client
        const httpProvider = await requireInstance('http');
        const httpClient = httpProvider.createClient('some_key');
        return { 
          httpClient: httpProvider.createClient('some_key'),
          endpoint: '/custom/services'
        };
      }
    );
});

Setting a custom service discovery client

If a custom service discovery client is required, the client can be configured as follows:

enableServiceDiscovery(
  configurator, 
  async(builder: ServiceDiscoveryConfigurator) => {
    builder.setServiceDiscoveryClient(
      {
        resolveServices() {
          return [
            { 
              key: 'service1', 
              url: 'http://service1.com' 
            },
            { 
              key: 'service2', 
              url: 'http://service2.com' 
            }
          ]
        },
        resolveService(key: string): Promise<ServiceEndpoint> {
          return this.services.find(s => s.key === key);
        }
      }
    );
});

If custom logic for creating the service discovery client is required, the client can be configured as follows:

enableServiceDiscovery(
  configurator, 
  async(builder: ServiceDiscoveryConfigurator) => {
    builder.setServiceDiscoveryClient(
      async(args: ConfigBuilderCallbackArgs) => {
        const httpProvider = await requireInstance('http');
        const httpClient = httpProvider.createClient('my_key');
        return {
          resolveServices() {
            return httpClient.get('/services');
          },
          resolveService(key: string): Promise<ServiceEndpoint> {
            return httpClient.get(`/services/${key}`);
          }
        };
      }
    );
});