{"id":16186199,"url":"https://github.com/zenflow/composite-service-http-gateway","last_synced_at":"2025-07-16T05:40:44.856Z","repository":{"id":57204947,"uuid":"310952990","full_name":"zenflow/composite-service-http-gateway","owner":"zenflow","description":"Configurable http gateway service for use with composite-service","archived":false,"fork":false,"pushed_at":"2023-05-02T23:18:06.000Z","size":595,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T08:46:03.713Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zenflow.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-07T23:49:30.000Z","updated_at":"2023-05-21T20:47:08.000Z","dependencies_parsed_at":"2024-10-27T19:26:32.315Z","dependency_job_id":"fbad4bb2-6cc7-4aa7-a612-5d9f5d42e7e8","html_url":"https://github.com/zenflow/composite-service-http-gateway","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zenflow/composite-service-http-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fcomposite-service-http-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fcomposite-service-http-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fcomposite-service-http-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fcomposite-service-http-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zenflow","download_url":"https://codeload.github.com/zenflow/composite-service-http-gateway/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zenflow%2Fcomposite-service-http-gateway/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265485307,"owners_count":23774467,"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":[],"created_at":"2024-10-10T07:17:33.698Z","updated_at":"2025-07-16T05:40:44.806Z","avatar_url":"https://github.com/zenflow.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# composite-service-http-gateway\n\nConfigurable http gateway service for use with [`composite-service`](https://github.com/zenflow/composite-service#readme)\n\n[![npm version](https://img.shields.io/npm/v/composite-service-http-gateway)](http://npmjs.com/package/composite-service-http-gateway)\n[![CI status](https://img.shields.io/github/workflow/status/zenflow/composite-service-http-gateway/CI?logo=GitHub\u0026label=CI)](https://github.com/zenflow/composite-service-http-gateway/actions?query=branch%3Amaster)\n[![dependencies status](https://img.shields.io/david/zenflow/composite-service-http-gateway)](https://david-dm.org/zenflow/composite-service-http-gateway)\n[![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/zenflow/composite-service-http-gateway?logo=Code%20Climate)](https://codeclimate.com/github/zenflow/composite-service-http-gateway)\n[![Known Vulnerabilities](https://snyk.io/test/github/zenflow/composite-service-http-gateway/badge.svg?targetFile=package.json)](https://snyk.io/test/github/zenflow/composite-service-http-gateway?targetFile=package.json)\n[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)\n\n## Install\n\n```\n$ npm install composite-service composite-service-http-gateway\n```\n\n## Usage\n\nCall `configureHttpGateway` with a [`HttpGatewayConfig`](./src/HttpGatewayConfig.ts) object\nto get a `ServiceConfig` object you can use in your `CompositeServiceConfig`.\n\n```js\nconst { startCompositeService } = require(\"composite-service\");\nconst { configureHttpGateway } = require(\"composite-service-http-gateway\");\n\nconst apiPort = process.env.API_PORT || 8000;\nconst webPort = process.env.WEB_PORT || 8001;\nconst port = process.env.PORT || 3000;\n\nstartCompositeService({\n  services: {\n    api: {\n      cwd: `${__dirname}/api`,\n      command: \"node server.js\",\n      env: { PORT: apiPort },\n      ready: ctx =\u003e ctx.onceTcpPortUsed(apiPort),\n    },\n    web: {\n      cwd: `${__dirname}/web`,\n      command: `next start --port ${webPort}`,\n      ready: ctx =\u003e ctx.onceTcpPortUsed(webPort),\n    },\n    gateway: configureHttpGateway({\n      dependencies: [\"api\", \"web\"],\n      port,\n      routes: {\n        \"/admin\": { static: { root: `${__dirname}/admin/build` } },\n        \"/api\": { proxy: { target: `http://localhost:${apiPort}` } },\n        \"/\": { proxy: { target: `http://localhost:${webPort}` } },\n      },\n    }),\n  },\n});\n```\n\nThe [`HttpGatewayConfig`](./src/HttpGatewayConfig.ts) object defines\na `port`, a `host` (optional), a collection of `routes`, and an `onReady` hook (optional).\nAny additional properties will be included in the returned `ServiceConfig` (except `command` or `ready`).\n\n### Routes\n\nThe central property of `HttpGatewayConfig` is `routes`.\nIn this object, each key is an absolute URL path,\nand each value is configuration of how to handle requests to that path and all it's sub-paths.\n*Note that the order of entries is significant because\nrequests will be handled by the *first* matching route,\nhence putting the `/` route last in the example above.*\n\n### Handlers\n\nThere are currently two \"handlers\", or ways requests can be handled:\n\n| # | identifier | middleware | description\n| --- | --- | --- | ---\n| 1 | `proxy` | [`http-proxy-middleware`](https://github.com/chimurai/http-proxy-middleware#readme) | Proxy to another http service, typically a sibling composed service\n| 2 | `static` | [`serve-static`](https://github.com/expressjs/serve-static#readme) | Serve static files from the filesystem\n\nHandler config objects are mostly just passed along to the underlying middleware,\nso *please refer to the above-linked middleware documentation for details on configuration options*.\n\nThat said, the following handler config defaults are updated for convenience:\n\n| handler | config | original default | updated default | reason |\n| --- | --- | --- | --- | ---\n| `proxy` | `logLevel` | `\"info\"` | `\"warn\"` | reduce noise\n| `proxy` | `ws` | `false` | `true` | support WebSocket connections out-of-the-box\n\n### Using functions in handler configuration\n\nNon-json-serializable values like functions and regular expressions can be used in handler configuration\nthanks to [`serialize-javascript`](https://github.com/yahoo/serialize-javascript).\nThis however comes with caveats:\n1. Functions must be pure (i.e. must not refer to variables outside it's definition)\n2. `require()`s inside a function will be resolved from`node_modules/composite-service-http-gateway/server/server.js` (3 levels)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenflow%2Fcomposite-service-http-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzenflow%2Fcomposite-service-http-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzenflow%2Fcomposite-service-http-gateway/lists"}