@casterly/express
Advanced tools
Comparing version 0.8.0 to 0.9.0-alpha.0
@@ -0,2 +1,3 @@ | ||
import './globals'; | ||
import type { RequestHandler } from 'express'; | ||
export declare const createRequestHandler: () => RequestHandler; |
140
lib/index.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createRequestHandler = void 0; | ||
require("./globals"); | ||
var stream_1 = require("stream"); | ||
var core_1 = require("@casterly/core"); | ||
// @ts-ignore | ||
var minipass_fetch_1 = require("minipass-fetch"); | ||
var createRequestHandler = function () { | ||
var handleRequest = core_1.createRequestHandler(); | ||
return function (req, res, next) { | ||
var _a; | ||
var request = new Request((_a = req.url) !== null && _a !== void 0 ? _a : '/', { | ||
method: req.method, | ||
headers: Object.entries(req.headers).map(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return [ | ||
key, | ||
Array.isArray(value) ? value : value === null || value === void 0 ? void 0 : value.toString(), | ||
]; | ||
}), | ||
}); | ||
var responseHeaders = new Headers(Object.entries(res.getHeaders()).map(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return [ | ||
key, | ||
Array.isArray(value) ? value : value === null || value === void 0 ? void 0 : value.toString(), | ||
]; | ||
})); | ||
handleRequest(request, responseHeaders) | ||
.then(function (response) { | ||
res.statusCode = response.status; | ||
for (var _i = 0, _a = Object.keys(res.getHeaders()); _i < _a.length; _i++) { | ||
var header = _a[_i]; | ||
res.removeHeader(header); | ||
return function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
var request, responseHeaders, writable, response, _i, _a, key, err_1; | ||
var _b, _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
request = new global.Request((_b = req.url) !== null && _b !== void 0 ? _b : '/', { | ||
method: req.method, | ||
headers: Object.entries(req.headers).map(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return [ | ||
key, | ||
Array.isArray(value) ? value : value === null || value === void 0 ? void 0 : value.toString(), | ||
]; | ||
}), | ||
}); | ||
responseHeaders = new global.Headers(Object.entries(res.getHeaders()).map(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return [ | ||
key, | ||
Array.isArray(value) ? value : value === null || value === void 0 ? void 0 : value.toString(), | ||
]; | ||
})); | ||
writable = new stream_1.Writable(); | ||
writable.write = res.write.bind(res); | ||
writable.destroy = res.destroy.bind(res); | ||
writable.end = res.end.bind(res); | ||
writable.cork = res.cork.bind(res); | ||
writable.uncork = res.uncork.bind(res); | ||
_d.label = 1; | ||
case 1: | ||
_d.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, handleRequest(request, responseHeaders, { | ||
responseStream: writable, | ||
})]; | ||
case 2: | ||
response = _d.sent(); | ||
res.status(response.status); | ||
for (_i = 0, _a = res.getHeaderNames(); _i < _a.length; _i++) { | ||
key = _a[_i]; | ||
res.removeHeader(key); | ||
} | ||
Object.entries((_c = response.outgoingHeaders) !== null && _c !== void 0 ? _c : {}).forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
res.set(key, value); | ||
}); | ||
if (response.body == null) { | ||
res.end(); | ||
} | ||
else if (typeof response.body === 'object' && 'pipe' in response.body) { | ||
if (response.body !== writable) { | ||
response.body.pipe(res); | ||
} | ||
if (typeof response.onReadyToStream === 'function') { | ||
response.onReadyToStream(); | ||
} | ||
} | ||
else { | ||
res.end(response.body); | ||
} | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_1 = _d.sent(); | ||
next(err_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
response.headers.forEach(function (value, key) { | ||
res.setHeader(key, value); | ||
}); | ||
minipass_fetch_1.Response.writeToStream(res, response); | ||
}) | ||
.catch(function (err) { | ||
next(err); | ||
}); | ||
}; | ||
}); }; | ||
}; | ||
exports.createRequestHandler = createRequestHandler; |
{ | ||
"name": "@casterly/express", | ||
"version": "0.8.0", | ||
"version": "0.9.0-alpha.0", | ||
"description": "Casterly bindings for Express.js", | ||
@@ -52,5 +52,5 @@ "author": "Lucas Cordeiro <ecdb.lucas@gmail.com>", | ||
"dependencies": { | ||
"@casterly/core": "^0.8.0" | ||
"@casterly/core": "^0.9.0-alpha.0" | ||
}, | ||
"gitHead": "a72f06ecc0585ef70a39c10570ac9e30053cddd3" | ||
"gitHead": "2e50a3096623dab024dad74f4e3196330a837945" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9191
9
125
+ Added@casterly/components@0.9.0-alpha.12(transitive)
+ Added@casterly/core@0.9.0-alpha.12(transitive)
+ Added@casterly/utils@0.9.0-alpha.12(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedreact-router@6.28.1(transitive)
+ Addedreact-router-dom@6.28.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removed@casterly/core@0.8.0(transitive)
- Removed@casterly/utils@0.8.0(transitive)
- Removed@gar/promisify@1.1.3(transitive)
- Removed@npmcli/fs@1.1.1(transitive)
- Removed@npmcli/move-file@1.1.2(transitive)
- Removed@tootallnate/once@1.1.2(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedagentkeepalive@4.5.0(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcacache@15.3.0(transitive)
- Removedchownr@2.0.0(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddebug@4.4.0(transitive)
- Removedencoding@0.1.13(transitive)
- Removederr-code@2.0.3(transitive)
- Removedfs-minipass@2.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedhttp-proxy-agent@4.0.1(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removedhumanize-ms@1.2.1(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedinfer-owner@1.0.4(transitive)
- Removedinflight@1.0.6(transitive)
- Removedip-address@9.0.5(transitive)
- Removedis-lambda@1.0.1(transitive)
- Removedjsbn@1.1.0(transitive)
- Removedlru-cache@6.0.0(transitive)
- Removedmake-fetch-happen@8.0.14(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminipass@3.3.65.0.0(transitive)
- Removedminipass-collect@1.0.2(transitive)
- Removedminipass-fetch@1.4.1(transitive)
- Removedminipass-flush@1.0.5(transitive)
- Removedminipass-pipeline@1.2.4(transitive)
- Removedminipass-sized@1.0.3(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-map@4.0.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpromise-inflight@1.0.1(transitive)
- Removedpromise-retry@2.0.1(transitive)
- Removedreact-router@6.28.0(transitive)
- Removedreact-router-dom@6.28.0(transitive)
- Removedretry@0.12.0(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsemver@7.6.3(transitive)
- Removedsmart-buffer@4.2.0(transitive)
- Removedsocks@2.8.3(transitive)
- Removedsocks-proxy-agent@5.0.1(transitive)
- Removedsprintf-js@1.1.3(transitive)
- Removedssri@8.0.1(transitive)
- Removedtar@6.2.1(transitive)
- Removedunique-filename@1.1.1(transitive)
- Removedunique-slug@2.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedyallist@4.0.0(transitive)