{"id":16592282,"url":"https://github.com/quantizor/middleware-proxy","last_synced_at":"2025-03-06T15:43:15.265Z","repository":{"id":57296846,"uuid":"59026796","full_name":"quantizor/middleware-proxy","owner":"quantizor","description":"↪ connect-compliant middleware for simple, transparent redirection of HTTP requests","archived":false,"fork":false,"pushed_at":"2018-10-02T17:31:51.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-04T12:04:33.200Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quantizor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-17T13:51:42.000Z","updated_at":"2019-03-21T19:46:43.000Z","dependencies_parsed_at":"2022-09-02T07:40:16.941Z","dependency_job_id":null,"html_url":"https://github.com/quantizor/middleware-proxy","commit_stats":null,"previous_names":["quantizor/middleware-proxy","probablyup/middleware-proxy"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantizor%2Fmiddleware-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantizor%2Fmiddleware-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantizor%2Fmiddleware-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quantizor%2Fmiddleware-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quantizor","download_url":"https://codeload.github.com/quantizor/middleware-proxy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241844301,"owners_count":20029613,"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-11T23:20:12.427Z","updated_at":"2025-03-06T15:43:15.240Z","avatar_url":"https://github.com/quantizor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# middleware-proxy\n\nThis is a simple tool that smooths the difficulties of working on integrated projects where the backend is hosted elsewhere from where you are developing your frontend. The proxy allows you to access your static HTML through a node server and redirect your RESTful calls to the implementing server.\n\n## usage\n\n```js\nconst proxy = require('middleware-proxy');\n\n/**\n * Returns a middleware function that selectively proxies incoming requests to another server.\n *\n * @param  {string|RegExp} matcher - used to detect if the middleware should be applied against the request URL\n * @param  {string} server - a fully qualified server address, e.g. http://localhost:8080\n * @param  {string} [path_to_strip] - (optional) a leading string that should be removed from the request URI\n *\n * @return {function} middleware, suitable for use in express or connect\n */\nproxy('/api/v1', 'http://localhost:8080')`\n```\n\n### basic express example\n\n```js\nconst express = require('express');\nconst app = express();\nconst http = require('http');\nconst proxy = require('middleware-proxy');\n\napp.configure(function() {\n    app.set('port', process.env.PORT || 3000);\n    app.use(express.static(__dirname + '/app'));\n});\n\napp.use(proxy('/service', 'http://localhost:8080'));\n\nhttp.createServer(app).listen(app.get('port'), function() {\n    console.log(`Express server listening on port ${app.get('port')}`);\n});\n```\n\nThis will send all requests starting with `/service` to `http://localhost:8080/service`.\n\n### using [budo](https://www.npmjs.com/package/budo) (a browserify livereload solution)\n\n```js\nconst proxy = require('middleware-proxy');\n\nrequire('budo')('index.js', {\n    browserify: {\n        debug: true,\n    },\n\n    host: '0.0.0.0',\n    live: true,\n    open: true,\n    portfind: true,\n    pushstate: true,\n    serve: 'assets/bundle.js',\n    stream: process.stdout,\n\n    middleware: [proxy('/service', 'http://localhost:8080')],\n});\n\n```\n\n## removing an API prefix\n\nLet's say your integration environment has chosen `/api` as the mount point for communicating with your application's backend APIs. However, you're building your frontend in a separate project and can't easily run a dev server that joins both functionalities. `middleware-proxy` solves this issue by allowing a third optional parameter that defines the part of the request URL to be stripped away when proxying the request to your destination host.\n\nAssuming your remote development API host is at `http://localhost:8080` and has a RESTful collection called `/posts`, you would write your AJAX calls to `GET` from `/api/posts` and use the following configuration:\n\n```js\nproxy('/api/posts', 'http://localhost:8080', '/api');\n```\n\nThe request is transparently redirected behind the scenes:\n\n```\nGET /api/posts -\u003e GET http://localhost:8080/posts\n```\n\n\u003csub\u003eBased on the work in [rgaskill/dev-rest-proxy](https://github.com/rgaskill/dev-rest-proxy)\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantizor%2Fmiddleware-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquantizor%2Fmiddleware-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantizor%2Fmiddleware-proxy/lists"}