Suggested answer

These three methods allow a custom cartridge to modify existing controller routes without redefining them from scratch. They are used after calling server.extend(require('controller/TargetController')):

1. server.append() — adds new middleware that runs AFTER all existing middleware steps in the route. Use this to post-process the view model, inject extra data into pdict, or trigger a side effect (such as logging or loyalty points update) after the main logic completes.
2. server.prepend() — inserts new middleware BEFORE all existing steps. Use this for pre-processing such as authentication checks, A/B test routing, or input sanitisation.
3. server.replace() — completely replaces all existing middleware for the named route with new middleware. Use this only when the original logic should not run at all. It is the most brittle option and can break with SFRA upgrades if the replaced logic changes.

In most cases, append or prepend are preferred over replace as they are less likely to conflict with future SFRA updates.

Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.

Community comments (0)

No comments yet.

Sign in or create a free account to add a comment. Comments are moderated before they appear.

Plain text only, 3–2000 characters. A moderator reviews every comment before it is published.