@rxts/koa-proxy
Version:
`http-proxy` wrapper as Koa middleware
16 lines (13 loc) • 1.8 kB
JavaScript
;function _interopDefault(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var httpProxy=_interopDefault(require("http-proxy"));
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function __rest(r,e){var t={};for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&e.indexOf(o)<0&&(t[o]=r[o]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(r);n<o.length;n++)e.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(r,o[n])&&(t[o[n]]=r[o[n]])}return t}var proxy=function(r){void 0===r&&(r={});var e=r.listeners,t=void 0===e?{}:e,o=r.override,n=r.skipError,i=__rest(r,["listeners","override","skipError"]),p=httpProxy.createProxyServer(i);return Object.keys(t).forEach((function(r){var e=t[r];e&&p.on(r,e)})),function(r,e){return new Promise((function(t,i){p.web(r.req,r.res,"function"==typeof o?o(r):void 0,(function(r){return r?n?t(e()):i(r):t()}))}))}};exports.default=proxy,exports.proxy=proxy;