{"id":13465035,"url":"https://github.com/kanongil/attache","last_synced_at":"2025-10-16T23:25:38.570Z","repository":{"id":1207700,"uuid":"41471865","full_name":"kanongil/attache","owner":"kanongil","description":"Register Hapi servers as a Consul service.","archived":false,"fork":false,"pushed_at":"2023-03-04T02:29:26.000Z","size":235,"stargazers_count":10,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-05T11:58:23.215Z","etag":null,"topics":["consul","hapi","hapi-plugin","health-check","javascript","service-registration"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanongil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-08-27T07:22:38.000Z","updated_at":"2021-06-22T09:31:27.000Z","dependencies_parsed_at":"2023-07-05T15:46:16.966Z","dependency_job_id":null,"html_url":"https://github.com/kanongil/attache","commit_stats":{"total_commits":57,"total_committers":3,"mean_commits":19.0,"dds":0.03508771929824561,"last_synced_commit":"672cd6f6dd42cd3424f12b72655cdb3e2222cd6f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanongil%2Fattache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanongil%2Fattache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanongil%2Fattache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanongil%2Fattache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanongil","download_url":"https://codeload.github.com/kanongil/attache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228327207,"owners_count":17902679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consul","hapi","hapi-plugin","health-check","javascript","service-registration"],"created_at":"2024-07-31T14:00:55.602Z","updated_at":"2025-10-16T23:25:38.456Z","avatar_url":"https://github.com/kanongil.png","language":"JavaScript","readme":"# attaché\n\nA [hapi.js](http://hapijs.com/) plugin that registers a [Consul](http://consul.io/) service.\n\n[![Build Status](https://travis-ci.org/kanongil/attache.svg?branch=master)](https://travis-ci.org/kanongil/attache)\n\n## Example\n\n```js\nconst Attache = require('attache');\nconst Hapi = require('@hapi/hapi');\n\nconst server = Hapi.Server();\n\nconst provision = async () =\u003e {\n\n    await server.register({\n        register: require('attache'),\n        options: {\n            service: {\n                name: 'myservice'\n            }\n        }\n    });\n\n    server.route({\n        method: 'GET',\n        path: '/',\n        handler() =\u003e {\n\n            return 'Hello World!';\n        }\n    });\n\n    server.route({\n        method: 'GET',\n        path: '/_health',\n        handler() =\u003e {\n\n            return 'OK';\n        }\n    });\n\n    await server.start();\n\n    console.log('Server started at', server.info.uri);\n});\n```\n\nThis will register a `\"myservice\"` service with Consul.\n\nThe service can be discovered using the standard Consul interfaces (eg. DNS or HTTP).\n\n## Usage\n\nInstall using `npm install attache`, and register with Hapi using `server.register()`.\n\n### Service registration \u0026 de-registration\n\nService registration is performed automatically as part of the `server.start()` processing.\n\nService de-registration is performed as part of the `server.stop()` processing. Once the server has started,\nit is important that `server.stop()` is called (and completed) before exiting the process.\nOtherwise, the service won't be deregistered. Note that `server.stop()` must also be called when `server.start()`\nreturns with an error.\n\n**If the service is not de-registered, it will linger in the Consul registry.** If configured with a health\ncheck, it will eventually be marked as unhealthy.\n\n### Plugin registration options\n\nAll configuration is optional:\n\n * `service` - Object containing service registration information:\n   * `name` - String with service name, as registered with Consul. Default: `\"hapi\"`.\n   * `check` - Object describing optional Consul health check:\n     * `path` - String with path to http health check endpoint. Return any `2xx` code to indicate \"passing\",\n                `429` for \"warning\", and any other response for \"failure\". If `false`, disables health check.\n                Default: `\"/_health\"`.\n     * `ttl` - Number with check interval in ms, or a String. Default: `undefined`.\n     * `interval` - Number with check interval in ms, or a String. Default: `\"5s\"`.\n     * `deregisterAfter` - Number with automatic critical service de-registration interval in ms,\n     or a String. Default: `\"120m\"`.\n     * `startHealthy` - Boolean, when set starts service in \"passing\" state. Default: `true`.\n * `retryStrategy` - async function that is passed `(consul, err, details)` when an automatic registration or\n                     de-registration fails. If a Number is returned, it is used as a delay before retrying.\n * `lowProfile`- Boolean that enables a low profile mode, which registers in the background and silences errors.\n * `consul` - Object with consul agent connection information:\n   * `host` - String with agent address. Default: `\"127.0.0.1\"`.\n   * `port` - Number with agent HTTP(s) port. Default: `8500`.\n   * `secure` - Boolean indicating if HTTPS is required. Default: `false`\n   * `ca` - Array of Strings or Buffers of trusted certificates in PEM format.\n\nIf a http health check is configured, you can either point it to an existing path, or preferably create a\ncustom route:\n\n```js\nserver.route({\n    method: 'GET',\n    path: '/_health',\n    handler() =\u003e {\n\n        return 'OK';\n    }\n});\n```\n\nNote that Consul does not use the returned value but it is recorded as part of the health check, useable\nfor debugging, etc.\n\nFor `ttl` checks, a periodic check-in within the ttl timeout is required. This can be done using the `consul`\nobject on the server, eg.:\n\n```js\nsetInterval(() =\u003e {\n\n    server.consul.checkin(true);\n}\n```\n\n### Custom service id options\n\nThe service is registered as a unique service instance.\nThe instance has a host unique ids, generated based on the service name, listening port, and process PID.\nAlternatively, a custom id and/or tags can be specified with the connection plugin option:\n\n```js\nHapi.Server({ plugins: { attache: { id: 'myservice-1', tags: ['hello'] } } });\n```\n\n### Consul class interface\n\nAvailable at `server.consul` once the plugin has been registered.\n\n#### `await checkin(isOk, [note])\n\nReports current status of the consul service when TTL checks are used. If it has not been called\nsuccessfully within the TTL interval since the last checkin, the health check will fail.\n\n * `isOk` - `true` indicates a \"passing\" state, `false` a \"failing\", and anything else is a \"warning\".\n * `note` - String with optional note that is recorded by consul.\n\n### Logging\n\nAll internal logging is tagged with `attache` and performed at the server level.\nAny de-registration errors are only exposed through this mechanism.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanongil%2Fattache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanongil%2Fattache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanongil%2Fattache/lists"}