This package exposes an express middleware, that fetches som predefined blocks from Cortina CMS.
The blocks are then stored in res.locals.blocks
, for use in Handlebars or similar.
Blocks can optionaly be cached in Redis.
npm install @kth/cortina-block
import { cortinaMiddleware } from '@kth/cortina-block'
apply middleware
server.use(
'',
cortinaMiddleware({
blockApiUrl,
blocksConfig,
redisConfig,
})
)
Default blocks that will be fetched can be found in config.ts. If you want to fetch other blocks or override the id of the default blocks, provide the optional blocksConfig
.
blockApiUrl
is required. Should point to the Cortina block API endpoint.memoryCache
is optional. Defaults to "true" unlessredisConfig
is provided. Stores blocks in memory for 10 minutes.redisConfig
is optional. An object parsed fromkth-node-configuration
, containinghost
andport
. If provided, blocks will be cached in redis.redisKey
is optional. Use unique keys of multiple apps share the same redis.supportedLanguages
is optional. If app only uses a subset of the supported languages. Default is['sv', 'en']
.blocksConfig
is optional. It's a plain object containing Cortina block IDs. It can be used both to replace existing id's, and to add new blocks.const blocksConfig = { footer: '1.123456', // Replaces existing block studentMegaMenu: '1.1066510', // Adds a new block }
Blocks title, image and secondaryMenu are no longer used by the apps.
That also means that a bunch of config is no longer needed.
- Config headers is no longer used.
- Config localeText is no longer used.
- Config resourceUrl is no longer used.
- Config siteName is no longer used.
- Config useStyle10 is no longer used.
- Config addBlocks has been renamed to blocksConfig.
- Config blockUrl has been renamed to blockApiUrl.
- Config blockVersion is no longer used.
- Config globalLink is no longer used.
- Config hostUrl is no longer used.
- Config proxyPrefixPath is no longer used.
- Config useStyle10 is no longer used.
All fetched blocks will be avalible on res.locals.blocks
.
{
megaMenu: "\n\n\n\n <nav class=\"b…\n </nav>\n\n \n\n",
footer: "\n\n\n <div class=\"blo… </div>\n </div>\n\n\n",
search: "\n\n\n <div class=\"blo…aded=!0);</script>\n\n\n",
etc..
}