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