@kth/cortina-block
Advanced tools
Comparing version 6.1.1 to 6.1.2
import { NextFunction, Request } from 'express'; | ||
import { Config, RedisConfig, SupportedLang, BlocksObject, BlocksConfig, Redis } from './types'; | ||
export * from './types'; | ||
export declare function cortina(blockApiUrl: string, headers: Headers | undefined, language: SupportedLang, blocksConfigIn?: BlocksConfig, redisConfig?: RedisConfig, redisClient?: Redis): Promise<{ | ||
export declare function cortina(blockApiUrl: string, headers: Headers | undefined, language: SupportedLang, shouldSkipCookieScripts: boolean, blocksConfigIn?: BlocksConfig, redisConfig?: RedisConfig, redisClient?: Redis): Promise<{ | ||
[blockName: string]: string; | ||
@@ -6,0 +6,0 @@ }>; |
@@ -29,4 +29,8 @@ "use strict"; | ||
// Gets HTML blocks from Cortina using promises. | ||
function cortina(blockApiUrl, headers, language, blocksConfigIn, redisConfig, redisClient) { | ||
function cortina(blockApiUrl, headers, language, shouldSkipCookieScripts, blocksConfigIn, redisConfig, redisClient) { | ||
const blocksConfig = { ...config_1.defaultBlocksConfig, ...blocksConfigIn }; | ||
if (shouldSkipCookieScripts) { | ||
blocksConfig.klaroConfig = '1.1011389'; | ||
blocksConfig.matomoAnalytics = '1.714097'; | ||
} | ||
if (!blockApiUrl) { | ||
@@ -86,3 +90,3 @@ throw new Error('Block api url must be specified.'); | ||
} | ||
const { redisConfig } = config; | ||
const { redisConfig, skipCookieScriptsInDev = true } = config; | ||
let redisClient; | ||
@@ -96,3 +100,7 @@ if (redisConfig) { | ||
[lang] = config_1.supportedLanguages; | ||
return cortina(config.blockApiUrl, config.headers, lang, config.blocksConfig, redisConfig, redisClient) | ||
let shouldSkipCookieScripts = false; | ||
if (req.hostname.includes('localhost') && skipCookieScriptsInDev) { | ||
shouldSkipCookieScripts = true; | ||
} | ||
return cortina(config.blockApiUrl, config.headers, lang, shouldSkipCookieScripts, config.blocksConfig, redisConfig, redisClient) | ||
.then(blocks => { | ||
@@ -99,0 +107,0 @@ // @ts-ignore |
@@ -15,2 +15,3 @@ export type Config = { | ||
redisConfig?: RedisConfig; | ||
skipCookieScriptsInDev?: boolean; | ||
}; | ||
@@ -17,0 +18,0 @@ export type RedisConfig = { |
{ | ||
"name": "@kth/cortina-block", | ||
"version": "6.1.1", | ||
"version": "6.1.2", | ||
"description": "Node.js module for fetching Cortina blocks and optionally cache using Redis.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
19371
333