CCD-102 practice question 3 of 30
Server.get(‘Show’, consentTracking.consent, cache.applyDefaultCache, function (req,res,next){ Var Site = require(‘dw/system/Syte”); Var…
Full set: 206 questionsServer.get(‘Show’, consentTracking.consent, cache.applyDefaultCache, function (req,res,next){ Var Site = require(‘dw/system/Syte”); Var pageMetaHelpter = require(‘*/cartridge/scripts/helpers/pageMetaHelper’); pageMetaHelpter.setPageMetaTags(req.pageMetaData, Site.current); res.render(‘/home/homePage’); Missing code here }, pageMetadata.computedPageMetadata); The controller endpoint code snippet above does not work. Which line of code should the developer use to replace line 6 and correct the problem?
The code snippet utilizes the server module from the Salesforce B2C Commerce Storefront Reference Architecture (SFRA), which follows an Express.js-like middleware pattern. In this pattern, multiple functions can process a request in a specific sequence. The next() function is a callback that passes control to the next middleware function in the chain. In the provided code, pageMetadata.computedPageMetadata is defined as a middleware function to be executed after the main route handler. Therefore, to invoke it and complete the chain, the main handler must call next(); after it has finished its own processing (like res.render).
B. return res;: Returning the response object does not pass control to the next middleware. The function's return value is typically ignored by the server module's routing mechanism.
C. res.next();: This is syntactically incorrect. The next function is passed as a direct argument to the middleware handler, not as a method of the res (response) object.
D. req.next();: This is syntactically incorrect. The next function is passed as a direct argument to the middleware handler, not as a method of the req (request) object.
1. Salesforce B2C Commerce Documentation: In the Storefront Reference Architecture (SFRA) documentation
the section on controllers explicitly describes this behavior. It states
"The server module uses the Express.js routing system... Each argument after the route name is a function that is executed in order. These functions are sometimes called middleware... To continue to the next function in the chain
the function must call the next() method."
Source: Salesforce Help Portal
B2C Commerce
Develop for SFRA
"Controllers in SFRA".
2. Express.js Official Documentation: The SFCC server module's design is based on Express.js. The official Express.js documentation on middleware clearly defines the role of next(). "A middleware function... can... Call the next middleware function in the stack."
Source: Express.js Documentation
"Writing middleware for use in Express apps"
expressjs.com/en/guide/writing-middleware.html.
3. University Courseware (MIT OpenCourseWare): Courses on modern web development frequently cover the Node.js/Express middleware pattern. Lecture notes explain that next() is the essential mechanism for invoking the subsequent function in the request-handling pipeline.
Source: MIT OpenCourseWare
6.170 Software Studio
Spring 2013
Lecture 15: "Node.js and Express"
Section on "Middleware".
Keep practicing
Take the free CCD-102 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CCD-102 practice questions
- Question 1A developer has a sandbox with code to log a message during execution, and the following …
- Question 4A developer needs to update the package.json file so that it points to the hock file for …
- Question 5A developer wants to create in Business Manager extension with the cartridge named plugin…
- Question 6A client uses tax tables in Business Manager to calculate tax. They recently started ship…
- Question 7A Digital Developer has a site export file on their computer that needs to be imported in…
- Question 8The developer created a new Storefront category in storefront-catalog-m-en, but when view…
