node-iframe
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -42,7 +42,8 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.configureCacheControl = exports.fetchFrame = void 0; | ||
exports.configureCacheControl = exports.configureTemplates = exports.fetchFrame = void 0; | ||
var is_url_1 = __importDefault(require("is-url")); | ||
var cheerio_1 = __importDefault(require("cheerio")); | ||
var isomorphic_unfetch_1 = __importDefault(require("isomorphic-unfetch")); | ||
var cheerio_1 = require("cheerio"); | ||
var templates_1 = require("@app/templates"); | ||
exports.configureTemplates = templates_1.configureTemplates; | ||
var config_1 = require("@app/config"); | ||
@@ -87,4 +88,11 @@ var cache_1 = require("@app/cache"); | ||
} | ||
function renderHtml(_a) { | ||
function renderErrorHtml(_a) { | ||
var url = _a.url, server = _a.server, _b = _a.noPage, noPage = _b === void 0 ? false : _b; | ||
return Object.assign(cheerio_1.load(!url | ||
? templates_1.templateModel[templates_1.TemplateType.error] | ||
: templates_1.templateModel[templates_1.TemplateType.notFound]), server ? { status: Number("" + 40 + (!url || noPage ? 4 : 0)) } : {}); | ||
} | ||
function renderHtml(_a, server) { | ||
var url = _a.url, baseHref = _a.baseHref; | ||
if (server === void 0) { server = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -96,3 +104,3 @@ var cachedHtml, e_1, response, html, $html_1, e_2; | ||
if (!is_url_1["default"](url)) { | ||
return [2, null]; | ||
return [2, renderErrorHtml({ url: url, server: server })]; | ||
} | ||
@@ -106,3 +114,3 @@ _b.label = 1; | ||
if (cachedHtml) { | ||
return [2, cheerio_1["default"].load(cachedHtml)]; | ||
return [2, cheerio_1.load(cachedHtml)]; | ||
} | ||
@@ -125,3 +133,3 @@ return [3, 4]; | ||
html = _b.sent(); | ||
$html_1 = cheerio_1["default"].load(html); | ||
$html_1 = cheerio_1.load(html); | ||
if ($html_1) { | ||
@@ -136,2 +144,5 @@ $html_1("head").prepend("<base target=\"_self\" href=\"" + url + "\">"); | ||
} | ||
if (server) { | ||
$html_1.status = 200; | ||
} | ||
return [2, $html_1]; | ||
@@ -142,3 +153,3 @@ case 7: | ||
return [3, 8]; | ||
case 8: return [2, false]; | ||
case 8: return [2, renderErrorHtml({ url: url, server: server, noPage: true })]; | ||
} | ||
@@ -148,27 +159,13 @@ }); | ||
} | ||
var renderError = function (res) { return res.status(400).send(templates_1.WEBSITE_NOT_FOUND_TEMPLATE); }; | ||
function createIframe(req, res, next) { | ||
var _this = this; | ||
res.createIframe = function (model) { return __awaiter(_this, void 0, void 0, function () { | ||
var $html, e_3; | ||
var $html; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
if (!model.url) { | ||
res.status(404).send(templates_1.NO_URL_TEMPLATE); | ||
} | ||
return [4, renderHtml(model)]; | ||
case 0: return [4, renderHtml(model, true)]; | ||
case 1: | ||
$html = _a.sent(); | ||
typeof ($html === null || $html === void 0 ? void 0 : $html.html) === "function" | ||
? res.status(200).send($html.html()) | ||
: renderError(res); | ||
return [3, 3]; | ||
case 2: | ||
e_3 = _a.sent(); | ||
console.error(e_3); | ||
renderError(res); | ||
return [3, 3]; | ||
case 3: return [2]; | ||
res.status(($html === null || $html === void 0 ? void 0 : $html.status) || 200).send($html.html()); | ||
return [2]; | ||
} | ||
@@ -181,18 +178,9 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var $html, e_4; | ||
var $html; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 3, , 4]); | ||
if (!(model === null || model === void 0 ? void 0 : model.url)) return [3, 2]; | ||
return [4, renderHtml(model)]; | ||
case 0: return [4, renderHtml(model, typeof process !== "undefined")]; | ||
case 1: | ||
$html = _a.sent(); | ||
return [2, ($html === null || $html === void 0 ? void 0 : $html.html()) || templates_1.WEBSITE_NOT_FOUND_TEMPLATE]; | ||
case 2: return [2, templates_1.NO_URL_TEMPLATE]; | ||
case 3: | ||
e_4 = _a.sent(); | ||
console.error(e_4); | ||
return [2, templates_1.WEBSITE_NOT_FOUND_TEMPLATE]; | ||
case 4: return [2]; | ||
return [2, $html === null || $html === void 0 ? void 0 : $html.html()]; | ||
} | ||
@@ -199,0 +187,0 @@ }); |
@@ -10,6 +10,11 @@ "use strict"; | ||
exports.__esModule = true; | ||
var not_found_1 = require("./not-found"); | ||
__createBinding(exports, not_found_1, "WEBSITE_NOT_FOUND_TEMPLATE"); | ||
var no_url_1 = require("./no-url"); | ||
__createBinding(exports, no_url_1, "NO_URL_TEMPLATE"); | ||
var pages_1 = require("./pages"); | ||
__createBinding(exports, pages_1, "WEBSITE_NOT_FOUND_TEMPLATE"); | ||
__createBinding(exports, pages_1, "NO_URL_TEMPLATE"); | ||
var build_configure_1 = require("./build-configure"); | ||
__createBinding(exports, build_configure_1, "configureTemplates"); | ||
var config_1 = require("./config"); | ||
__createBinding(exports, config_1, "TemplateType"); | ||
var build_1 = require("./build"); | ||
__createBinding(exports, build_1, "templateModel"); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "node-iframe", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "create a iframe on your server to bypass CORS issues. ( reverse engineer security issues )", | ||
@@ -5,0 +5,0 @@ "main": "dist/iframe.js", |
@@ -37,7 +37,17 @@ # node-iframe | ||
```typescript | ||
const { fetchFrame, configureCacheControl } = require("node-iframe"); | ||
const { | ||
fetchFrame, | ||
configureCacheControl, | ||
configureTemplates, | ||
} = require("node-iframe"); | ||
// optional: configure cache-control | ||
/* optional: configure cache-control - check https://github.com/node-cache/node-cache#options | ||
* for more options and info | ||
**/ | ||
configureCacheControl({ stdTTL: 0, checkperiod: 600 }); | ||
// optional: configure error-pages - check src/templates for more info | ||
// 0: error, 1: not-found, 2: all templates check src/templates/config for options | ||
configureTemplates("<div>No Fish found</div>", 1); | ||
async function fetchIframe() { | ||
@@ -44,0 +54,0 @@ return await fetchFrame("/iframe/?url=https://www.etsy.com"); |
@@ -0,5 +1,6 @@ | ||
import { configureTemplates } from "@app/templates"; | ||
import { configureCacheControl } from "@app/cache"; | ||
declare function createIframe(req: any, res: any, next: any): void; | ||
export declare function fetchFrame(model: any): Promise<any>; | ||
export { configureCacheControl }; | ||
export { configureTemplates, configureCacheControl }; | ||
export default createIframe; |
@@ -1,2 +0,4 @@ | ||
export { WEBSITE_NOT_FOUND_TEMPLATE } from "./not-found"; | ||
export { NO_URL_TEMPLATE } from "./no-url"; | ||
export { WEBSITE_NOT_FOUND_TEMPLATE, NO_URL_TEMPLATE } from "./pages"; | ||
export { configureTemplates } from "./build-configure"; | ||
export { TemplateType } from "./config"; | ||
export { templateModel } from "./build"; |
@@ -1,1 +0,1 @@ | ||
export { fetchWithTimestamps } from "./metrics"; | ||
export { fetchWithTimestamps, TimeStampMetrics } from "./metrics"; |
@@ -6,8 +6,10 @@ interface FetchParams { | ||
} | ||
interface FetchResponse { | ||
res: string; | ||
export declare type TimeStampMetrics = { | ||
t0: number; | ||
t1: number; | ||
}; | ||
interface FetchResponse extends TimeStampMetrics { | ||
res: string; | ||
} | ||
declare const fetchWithTimestamps: ({ url, operation, log, }: FetchParams) => Promise<FetchResponse>; | ||
export { fetchWithTimestamps }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
34280
59
490
72