UNPKG

edge-mock

Version:

types for testing an developer edge applications

22 lines 863 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const models_1 = require("./models"); const Request_1 = require("./models/Request"); async function stub_fetch(resource, init = {}) { const method = Request_1.check_method(init.method); let url; if (typeof resource == 'string') { url = new URL(resource); } else { url = resource; } if (url.href == 'https://example.com/') { return new models_1.EdgeResponse('<h1>response from example.com</h1>', { status: 200, headers: { 'content-type': 'text/html' } }, url.href, { init }); } else { return new models_1.EdgeResponse(`404 response from ${method}: ${url.href}`, { status: 404, headers: { 'content-type': 'text/plain' } }, url.href, { init }); } } exports.default = stub_fetch; //# sourceMappingURL=stub_fetch.js.map