Skip to Content
TemplateConfigurationHosted vs local configurations

How to manage hosted and local configurations

The Sharetribe Web Template has a number of configurations that can be used to customise the template with low code effort. Starting in version v2.0.0, the template can also use asset-based configurations, if they are defined in Sharetribe Console.

The Asset Delivery API  is used to fetch no-code content and configurations, defined in the Console, to your client application. See all the available assets.

Sharetribe Web Template fetches mandatory assets by default.

Some configurations are mandatory to define in Sharetribe Console, such as logo, listing types, listing fields, and minimum transaction size. Those configurations are read from the hosted assets in the template by default. This means that if you want to, for instance, add a listing type with a custom transaction process, or add a custom listing field in the template code, you will need to modify how configurations get merged in the template.

How configurations are merged in the template

The template uses a function mergeConfig  in src/config/mergeConfig.js to merge hosted assets and local configurations.

└── src └── config └── mergeConfig.js
src/config/mergeConfig.js
export const mergeConfig = (configAsset = {}, defaultConfigs = {}) => { // Remove trailing slash from marketplaceRootURL if any const marketplaceRootURL = defaultConfigs.marketplaceRootURL; const cleanedRootURL = typeof marketplaceRootURL === 'string' ? marketplaceRootURL.replace(/\/$/, '') : ''; // App-config slices from registered handlers // (normalize -> validate -> resolve). // Keys match handler.id (e.g. analytics, listing, search, user). // Hosted configs win when usable; built-in defaults fill gaps. const { resolved: appConfigs, configIssues } = applyConfigHandlers({ hosted: configAsset, defaults: defaultConfigs, handlers: configHandlers, }); // Derived top-level convenience keys const listingMinimumPriceSubUnits = getListingMinimumPriceSubUnits( appConfigs.transaction, defaultConfigs.listingMinimumPriceSubUnits ); const currency = getMarketplaceCurrency( appConfigs.localization, defaultConfigs.currency ); return { ...defaultConfigs, marketplaceRootURL: cleanedRootURL, listingMinimumPriceSubUnits, currency, hasMandatoryConfigurations: hasMandatoryConfigurations(configIssues), // Handler-built slices override defaultConfigs ...appConfigs, }; };

The mergeConfig function delegates each configuration domain to a registered config handler via applyConfigHandlers. Each handler follows a normalize → validate → resolve pipeline. The handlers are registered in the configHandlers array in the same mergeConfig.js  file.

For example, the listing handler in src/config/listing/listing.js controls how hosted and local listing types get merged. Its resolve function decides whether to use only hosted assets or to also include local defaults:

src/config/listing/listing.js
const resolve = (validated, defaults, ctx) => { /* ... */ const shouldMerge = mergeDefaultTypesAndFieldsForDebugging(false); const listingTypes = shouldMerge ? union(hostedListingTypes, defaultListingTypes, 'listingType') : hostedListingTypes; const listingFields = shouldMerge ? union(hostedListingFields, defaultListingFields, 'key') : hostedListingFields; /* ... */ };

By default, the listing handler uses only hosted listing types and fields. The mergeDefaultTypesAndFieldsForDebugging function controls whether local defaults are also merged in.

When debugging your code, you can toggle the parameter for mergeDefaultTypesAndFieldsForDebugging into true to show both local and hosted configurations.

Example: use both hosted and local configs for listing types

Let’s say you want to use multiple listing types in your marketplace – one for regular bookings, defined in Sharetribe Console, and one for negotiated bookings , defined in the template.

First, follow the directions in the process README.md to configure the template to use the new process. Then, make the following modification to the listing handler’s resolve function in src/config/listing/listing.js:

src/config/listing/listing.js
const resolve = (validated, defaults, ctx) => { /* ... */ const shouldMerge = mergeDefaultTypesAndFieldsForDebugging(false); const listingTypes = union(hostedListingTypes, defaultListingTypes, 'listingType'); const listingFields = shouldMerge ? union(hostedListingFields, defaultListingFields, 'key') : hostedListingFields; /* ... */

With this change, you are still retrieving listing fields and other configurations primarily from hosted configurations, and using default configurations only as a fallback. However, listing types now combine both hosted asset and default config listing types.

Last updated on