Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ilc/config/custom-environment-variables.json5
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
client: {
protocol: 'ILC_CLIENT_PROTOCOL',
},
tailor: {
maxFragmentRequestSize: 'ILC_MAX_FRAGMENT_REQUEST_SIZE',
},
experiments: {
enabled: 'ILC_EXPERIMENTS_ENABLED',
},
Expand Down
18 changes: 13 additions & 5 deletions ilc/config/default.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
port: 8233,
cdnUrl: null,
staticError: {
disasterFileContentPath: null
disasterFileContentPath: null,
},
registry: {
address: 'http://127.0.0.1:4001'
address: 'http://127.0.0.1:4001',
},
newrelic: {
licenseKey: null,
Expand All @@ -16,13 +16,13 @@
*/
customClientJsWrapper: null,
automaticallyInjectBrowserMonitoring: true,
appName: null
appName: null,
},
overrideConfigTrustedOrigins: null,
logger: {
accessLog: {
ignoreUrls: ''
}
ignoreUrls: '',
},
},
static: {
internalUrl: '/_ilc/',
Expand All @@ -33,6 +33,14 @@
client: {
protocol: 'https',
},
tailor: {
// Disabled by default: enabling it changes what renders, so a deployment opts in
// rather than inheriting the decision. Set it to the byte ceiling your fragment
// servers actually accept — below their --max-http-header-size, whose own default is
// 16384. For stock node fragments 15872 is a reasonable starting point. 0 keeps the
// guard off, and an unusable value leaves it off with a WARN at startup.
maxFragmentRequestSize: 0,
},
experiments: {
// Global kill-switch. Set to false (e.g. via env in an incident) to send every
// visitor to control with no assignment. Toggling this is a config change, not a deploy.
Expand Down
2 changes: 1 addition & 1 deletion ilc/server/TransitionHooksExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TransitionHooksExecutor {
meta: route.meta,
url: route.reqUrl,
hostname: req.host,
route: route.route,
route: route.route as string,
},
log: req.log,
req: req.raw,
Expand Down
3 changes: 2 additions & 1 deletion ilc/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { pingPluginFactroy } from './routes/pingPluginFactory';
import { renderTemplateHandlerFactory } from './routes/renderTemplateHandlerFactory';
import { wildcardRequestHandlerFactory } from './routes/wildcardRequestHandlerFactory';
import { registerStatic } from './serveStatic';
import tailorFactory from './tailor/factory';
import { tailorFactory } from './tailor/factory';
import { TransitionHooksExecutor } from './TransitionHooksExecutor';
const { Test500Error } = require('./errorHandler/ErrorHandler');

Expand Down Expand Up @@ -118,6 +118,7 @@ module.exports = async function createApplication(registryService, pluginManager
config.get('newrelic.customClientJsWrapper'),
autoInjectNrMonitoring,
logger,
config.get('tailor.maxFragmentRequestSize'),
);

app.all('*', wildcardRequestHandlerFactory(logger, registryService, errorHandler, transitionHooksExecutor, tailor));
Expand Down
4 changes: 2 additions & 2 deletions ilc/server/routes/wildcardRequestHandlerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { SlotCollection } from '../../common/Slot/SlotCollection';
import UrlProcessor from '../../common/UrlProcessor';
import i18n from '../i18n';
import CspBuilderService from '../services/CspBuilderService';
import tailorFactory from '../tailor/factory';
import { tailorFactory } from '../tailor/factory';
import { mergeConfigs, type OverrideConfig } from '../tailor/merge-configs';
import { buildForwardedHeaders } from '../utils/helpers';
import parseOverrideConfig from '../tailor/parse-override-config';
import ServerRouter from '../tailor/server-router';
import { ServerRouter } from '../tailor/server-router';
import { TransitionHooksExecutor } from '../TransitionHooksExecutor';
import { ErrorHandler } from '../types/ErrorHandler';
import { IlcRouteHandlerMethod } from '../types/IlcRouteHandlerMethod';
Expand Down
53 changes: 0 additions & 53 deletions ilc/server/tailor/factory.js

This file was deleted.

63 changes: 63 additions & 0 deletions ilc/server/tailor/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import newrelic from 'newrelic';

import { Tailor, type TailorOptions } from './tailorx';
import { fetchTemplate } from './fetch-template';
import { filterHeaders } from './filter-headers';
import errorHandlerSetup from './error-handler';
import fragmentHooks from './fragment-hooks';
import { ConfigsInjector } from './configs-injector';
import processFragmentResponse from './process-fragment-response';
import { requestFragmentFactory } from './request-fragment';
import type { ServerRouter } from './server-router';
import type { Registry } from '../types/Registry';

type Logger = Pick<Console, 'debug' | 'warn'>;

/**
* The error-handling service is injected by app.js and typed where it is defined; this module
* only passes it through, so it takes it as opaque.
*/
export function tailorFactory(
registryService: Registry,
errorHandlingService: unknown,
cdnUrl: string | null,
nrCustomClientJsWrapper: string | null = null,
nrAutomaticallyInjectClientScript = true,
logger: Logger,
maxFragmentRequestSize?: unknown,
) {
const configsInjector = new ConfigsInjector(
newrelic,
cdnUrl,
nrCustomClientJsWrapper,
nrAutomaticallyInjectClientScript,
);

const tailorOptions: TailorOptions = {
fetchContext: async function (request: { router: ServerRouter }) {
return request.router.getFragmentsContext();
},
fetchTemplate: fetchTemplate(configsInjector, newrelic, registryService),
requestFragment: requestFragmentFactory(filterHeaders, processFragmentResponse, logger, {
maxRequestSize: maxFragmentRequestSize,
}),
processFragmentResponse,
filterHeaders,
fragmentHooks: {
insertStart: fragmentHooks.insertStart.bind(null, logger),
insertEnd: fragmentHooks.insertEnd,
},
botsGuardEnabled: true,
getAssetsToPreload: configsInjector.getAssetsToPreload,
filterResponseHeaders: (attributes: unknown, headers: Record<string, unknown>) =>
'set-cookie' in headers ? { 'set-cookie': headers['set-cookie'] } : {},
baseTemplatesCacheSize: 1,
shouldSetPrimaryFragmentAssetsToPreload: false,
};

const tailor = new Tailor(tailorOptions);

errorHandlerSetup(tailor, errorHandlingService);

return tailor;
}
Loading
Loading