Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@casterly/express

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@casterly/express - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0-alpha.0

lib/globals.d.ts

1

lib/index.d.ts

@@ -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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc