Middleware and utilities to simulate a deployed MRT environment.
import {
createMRTProxyMiddlewares,
createMRTRequestProcessorMiddleware,
createMRTStaticAssetServingMiddleware,
createMRTCommonMiddleware,
createMRTCleanUpMiddleware,
isLocal,
} from '@salesforce/mrt-utilities';
export const createApp = (): Express => {
const app = express();
app.disable('x-powered-by');
// Top most middleware to set up headers
app.use(createMRTCommonMiddleware());
if (isLocal()) {
const requestProcessorPath = 'path/to/request-processor.js';
const proxyConfigs = [
{
host: 'https://example.com',
path: 'api',
},
];
app.use(createMRTRequestProcessorMiddleware(requestProcessorPath, proxyConfigs));
const mrtProxies = createMRTProxyMiddlewares(proxyConfigs);
mrtProxies.forEach(({ path, fn }) => {
app.use(path, fn);
});
const staticAssetDir = 'path/to/static';
app.use(
`/mobify/bundle/${process.env.BUNDLE_ID || '1'}/static/`,
createMRTStaticAssetServingMiddleware(staticAssetDir)
);
}
// Cleans up any remaining headers and sets any remaining values
app.use(createMRTCleanUpMiddleware());
Use the data-store subpath with Node's dev-data-store condition to load the pseudo local data-store implementation:
node --conditions dev-data-store your-app.jsimport {DataStore} from '@salesforce/mrt-utilities/data-store';
const store = DataStore.getDataStore();
const entry = await store.getEntry('custom-global-preferences');Configure local values with environment variables:
SFNEXT_DATA_STORE_DEFAULTS: JSON map of key to object valueSFNEXT_DATA_STORE_WARN_ON_MISSING: set tofalseto suppress missing-key warnings
Example:
export SFNEXT_DATA_STORE_DEFAULTS='{"custom-global-preferences":{"featureFlag":true}}'
export SFNEXT_DATA_STORE_WARN_ON_MISSING=trueBy default, missing keys still throw DataStoreNotFoundError in development (matching production semantics).