{"id":17419799,"url":"https://github.com/bendrucker/http-app-router","last_synced_at":"2025-07-02T13:35:41.742Z","repository":{"id":57268054,"uuid":"62664741","full_name":"bendrucker/http-app-router","owner":"bendrucker","description":"Request router for building HTTP proxy servers","archived":false,"fork":false,"pushed_at":"2018-11-13T19:20:16.000Z","size":49,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-28T13:43:19.663Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bendrucker.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}},"created_at":"2016-07-05T19:45:18.000Z","updated_at":"2018-12-19T23:58:28.000Z","dependencies_parsed_at":"2022-09-02T05:41:06.688Z","dependency_job_id":null,"html_url":"https://github.com/bendrucker/http-app-router","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/bendrucker/http-app-router","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fhttp-app-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fhttp-app-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fhttp-app-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fhttp-app-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bendrucker","download_url":"https://codeload.github.com/bendrucker/http-app-router/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fhttp-app-router/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263148687,"owners_count":23421226,"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-17T02:33:30.560Z","updated_at":"2025-07-02T13:35:41.700Z","avatar_url":"https://github.com/bendrucker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-app-router [![Build Status](https://travis-ci.org/bendrucker/http-app-router.svg?branch=master)](https://travis-ci.org/bendrucker/http-app-router) [![codecov](https://codecov.io/gh/bendrucker/http-app-router/branch/master/graph/badge.svg)](https://codecov.io/gh/bendrucker/http-app-router)\n\n\u003e Request router for building HTTP proxy servers\n\nhttp-app-router is a Node HTTP router designed for serving multiple HTML applications on the same domain. HTML applications might include:\n\n* A single page JavaScript web app\n* A CMS-powered blog\n* Static HTML content\n\nIf it speaks HTTP and sends HTML, it's an HTML app. Apps are defined with a server `host` and a list of `routes` that should match to that app. The router will make a request to your app and stream the response down to the client.\n\n\n## Install\n\n```\n$ npm install --save http-app-router\n```\n\n\n## Usage\n\nPass an array of `apps` to the `Router` contructor to create a router handler. Use that handler to route requests and send a response if an app matches the request. Handlers are `req, res, callback` functions that you can use with plain `http.Server` instances or connect/express apps.\n\nThe router will *always* send a response when fetching the app is successful and will *never* send an error response. That's up to you.\n\n```js\nvar Router = require('http-app-router')\nvar http = require('http')\n\nvar router = Router([\n  {\n    name: 'github',\n    host: 'github.com',\n    routes: [\n      '/bendrucker'\n    ]\n  },\n  {\n    name: 'local',\n    host: 'localhost',\n    routes: '*'\n  }\n])\n\nvar server = http.createServer(function (req, res) {\n  router(req, res, function (err) {\n    if (err) res.end('oh no, an error!')\n  })\n})\n```\n\n## API\n\n#### `Router(apps)` -\u003e `function`\n\nReturns a `router` function.\n\n##### app\n\n*Required*  \nType: `array[object]`\n\nAn array of app objects, containing:\n\n###### name\n\n*Required*  \nType: `string`  \n\nAn application name.\n\n###### host\n\n*Required*  \nType: `string`  \n\nThe application host.\n\n###### insecure\n\nType: `boolean`  \nDefault: `false`\n\nToggles the app to be fetched over plain HTTP instead of HTTPS.\n\n###### prefix\n\nType: `string`  \nDefault: `''`\n\nA prefix that will be removed from the URL before being passed along.\n\n###### headers\n\nType: `object`  \n\nOptional headers to set on requests.\n\n###### cookies\n\nType: `array[string]`\n\nA whitelist of cookie names that can be sent by a client or set by an app.\n\n###### transforms\n\nType: `array[string]`\n\nAn array of [`transform`](transforms.js) function keys that receive the `app` as an argument and return a [`Transform` stream](https://nodejs.org/api/stream.html#stream_class_stream_transform). The transform stream will receive and output HTML. \n\nBuilt in:\n\n* [absolute](github.com/bendrucker/absoluteify)\n\nOr add custom things, maybe minification or something equally practical:\n\n```js\nvar transforms = require('http-app-router/transforms')\nvar through = require('through2')\n\ntranforms.uppercase = function (app) {\n  return through(function (chunk, enc, callback) {\n    callback(null, chunk.toString().toUpperCase())\n  })\n}\n```\n\n#### `router.onLog(listener)` -\u003e `function`\n\nListens on log output from the router.\n\n##### listener\n\n*Required*  \nType: `function`  \nArguments: `{level, message}`\n\n## License\n\nMIT © [Ben Drucker](http://bendrucker.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fhttp-app-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbendrucker%2Fhttp-app-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fhttp-app-router/lists"}