@rxts/koa-proxy
Version:
`http-proxy` wrapper as Koa middleware
16 lines (13 loc) • 1.51 kB
JavaScript
import r from"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.
***************************************************************************** */const e=(e={})=>{var{listeners:t={},override:o,skipError:n}=e,p=function(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}(e,["listeners","override","skipError"]);const i=r.createProxyServer(p);return Object.keys(t).forEach(r=>{const e=t[r];e&&i.on(r,e)}),(r,e)=>new Promise((t,p)=>{i.web(r.req,r.res,"function"==typeof o?o(r):void 0,r=>r?n?t(e()):p(r):t())})};export default e;export{e as proxy};