Socket
Socket
Sign inDemoInstall

ssr-for-bots

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssr-for-bots - npm Package Compare versions

Comparing version 1.0.1-b to 1.0.1-c

10

lib/index.d.ts
import { NextFunction, Request, Response } from "express";
interface Options {
prerender: Array<string>;
exclude: Array<string>;
useCache: boolean;
cacheRefreshRate: number;
prerender?: Array<string>;
exclude?: Array<string>;
useCache?: boolean;
cacheRefreshRate?: number;
}
declare function ssrForBots(options: Options): (req: Request, res: Response, next: NextFunction) => void;
declare function ssrForBots(options?: Options): (req: Request, res: Response, next: NextFunction) => void;
export default ssrForBots;

@@ -48,3 +48,3 @@ "use strict";

function ssrForBots(options) {
options = Object.assign({
if (options === void 0) { options = {
prerender: [],

@@ -54,2 +54,8 @@ exclude: [],

cacheRefreshRate: 86400,
}; }
var applyOptions = Object.assign({
prerender: [],
exclude: [],
useCache: true,
cacheRefreshRate: 86400,
}, options);

@@ -94,6 +100,6 @@ // Default user agents

userAgent = req.headers["user-agent"] || "";
prerender = new RegExp(__spreadArrays(prerenderArray, options === null || options === void 0 ? void 0 : options.prerender).join("|").slice(0, -1), "i").test(userAgent);
exclude = !new RegExp(__spreadArrays(excludeArray, options === null || options === void 0 ? void 0 : options.exclude).join("|").slice(0, -1)).test(req.originalUrl);
prerender = new RegExp(__spreadArrays(prerenderArray, applyOptions.prerender).join("|").slice(0, -1), "i").test(userAgent);
exclude = !new RegExp(__spreadArrays(excludeArray, applyOptions.exclude).join("|").slice(0, -1)).test(req.originalUrl);
if (!(req.originalUrl && prerender && exclude)) return [3 /*break*/, 2];
return [4 /*yield*/, ssr_1.ssr(req.protocol + "://" + req.get("host") + req.originalUrl, options === null || options === void 0 ? void 0 : options.useCache, options === null || options === void 0 ? void 0 : options.cacheRefreshRate)];
return [4 /*yield*/, ssr_1.ssr(req.protocol + "://" + req.get("host") + req.originalUrl, applyOptions.useCache, applyOptions.cacheRefreshRate)];
case 1:

@@ -100,0 +106,0 @@ _a = _b.sent(), html = _a.html, status_1 = _a.status;

{
"name": "ssr-for-bots",
"version": "1.0.1b",
"version": "1.0.1c",
"description": "SSR-for-bots is an express middleware that will apply SSR to your application only when bots are visiting it",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -5,10 +5,17 @@ import { NextFunction, Request, Response } from "express";

interface Options {
prerender: Array<string>;
exclude: Array<string>;
useCache: boolean;
cacheRefreshRate: number;
prerender?: Array<string>;
exclude?: Array<string>;
useCache?: boolean;
cacheRefreshRate?: number;
}
function ssrForBots(options: Options) {
options = Object.assign(
function ssrForBots(
options: Options = {
prerender: [], // Array containing the user-agents that will trigger the ssr service
exclude: [], // Array containing paths and/or extentions that will be excluded from being prerendered by the ssr service
useCache: true, // Variable that determins if we will use page caching or not
cacheRefreshRate: 86400, // Seconds of which the cache will be kept alive, pass 0 or negative value for infinite lifespan
}
) {
let applyOptions = Object.assign(
{

@@ -60,3 +67,3 @@ prerender: [], // Array containing the user-agents that will trigger the ssr service

const prerender = new RegExp(
[...prerenderArray, ...options?.prerender].join("|").slice(0, -1),
[...prerenderArray, ...applyOptions.prerender].join("|").slice(0, -1),
"i"

@@ -66,3 +73,3 @@ ).test(userAgent);

const exclude = !new RegExp(
[...excludeArray, ...options?.exclude].join("|").slice(0, -1)
[...excludeArray, ...applyOptions.exclude].join("|").slice(0, -1)
).test(req.originalUrl);

@@ -73,4 +80,4 @@

req.protocol + "://" + req.get("host") + req.originalUrl,
options?.useCache,
options?.cacheRefreshRate
applyOptions.useCache,
applyOptions.cacheRefreshRate
);

@@ -77,0 +84,0 @@ return res.status(status).send(html);

Sorry, the diff of this file is not supported yet

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