You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
0 && (module.exports = {
|
|
interceptTestApis: null,
|
|
wrapRequestHandlerWorker: null,
|
|
wrapRequestHandlerNode: null
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
interceptTestApis: function() {
|
|
return interceptTestApis;
|
|
},
|
|
wrapRequestHandlerWorker: function() {
|
|
return wrapRequestHandlerWorker;
|
|
},
|
|
wrapRequestHandlerNode: function() {
|
|
return wrapRequestHandlerNode;
|
|
}
|
|
});
|
|
const _context = require("./context");
|
|
const _fetch = require("./fetch");
|
|
const _httpget = require("./httpget");
|
|
const reader = {
|
|
url (req) {
|
|
return req.url ?? "";
|
|
},
|
|
header (req, name) {
|
|
const h = req.headers[name];
|
|
if (h === undefined || h === null) {
|
|
return null;
|
|
}
|
|
if (typeof h === "string") {
|
|
return h;
|
|
}
|
|
return h[0] ?? null;
|
|
}
|
|
};
|
|
function interceptTestApis() {
|
|
const originalFetch = global.fetch;
|
|
const restoreFetch = (0, _fetch.interceptFetch)(originalFetch);
|
|
const restoreHttpGet = (0, _httpget.interceptHttpGet)(originalFetch);
|
|
// Cleanup.
|
|
return ()=>{
|
|
restoreFetch();
|
|
restoreHttpGet();
|
|
};
|
|
}
|
|
function wrapRequestHandlerWorker(handler) {
|
|
return (req, res)=>(0, _context.withRequest)(req, reader, ()=>handler(req, res));
|
|
}
|
|
function wrapRequestHandlerNode(handler) {
|
|
return (req, res, parsedUrl)=>(0, _context.withRequest)(req, reader, ()=>handler(req, res, parsedUrl));
|
|
}
|
|
|
|
//# sourceMappingURL=server.js.map
|