cs-icon.svg

Configuration

Warning: contentstack-express framework has been deprecated. We will soon stop supporting this framework. Instead, we recommend using DataSync, which is faster and more flexible than the web framework.

All the configuration for contentstack-express is stored in the file under the “config” folder. This config file is loaded for all the environments of your stack. If you want separate configuration for a specific environment, you can create a separate config file for that environment. For example, the “Development” environment will have development.js file, and “Production” will have production.js file.

Example

all.js
{
    theme: “basic”
}
staging.js
{
    theme: “advanced”
}

In the above example, when the application will run on the “staging” environment, the “advanced” theme will be implemented for templates and static files. For the rest of the environments, the basic theme will be implemented, as specified in all.js file.

Get configuration

To get the configuration, use the following command:

contentstack.config.get('key')

In the above command,  “key” is any key present in the “config” file.

For example, if we have mentioned a port value in the config file, we can get it by using the following command:

contentstack.config.get('port')

To get the nested-level JSON key, you can use the dot-separated syntax as given below:

contentstack.config.get('storage.options.baseDir')

The following are the various configurations that the user can use as per the requirement.

{
    cache: true,
    logs: {
        console: true,
        json: true,
        path: "./_logs"
    },
    view: {
        module: "nunjucks",
        extension: "html",
        scaffold: true,
        minify: true,
        options: {
                autoescape: false,
                throwOnUndefined: false,
                trimBlocks: false,
                lstripBlocks: false,
                watch: true,
                noCache: true    
        }
    },
    languages: [
        {
            code: "en-us",
            relative_url_prefix: "/"
        }
    ],
    storage: {
        provider: "FileSystem",
        options: {
            basedir: "./_content"
        }
    },
    assets: {
        pattern: "/assets/:uid/:filename",
        basedir: "./_content",
        options: {
            dotfiles: 'ignore',
            etag: true,
            extensions: [ 'html', 'htm'],
            fallthrough: true,
            index: 'index.html',
            lastModified: true,
            maxAge: 0,
            redirect: true,
            setHeaders: function (res, path, stat) {
                res.set('x-timestamp', Date.now());
            }
        }
    },
    "static": {
        url: "/static",
        path: "public",
        options: {
            dotfiles: 'ignore',
            etag: true,
            extensions: [ 'html', 'htm'],
            fallthrough: true,
            index: 'index.html',
            lastModified: true,
            maxAge: 0,
            redirect: true,
            setHeaders: function (res, path, stat) {
                res.set('x-timestamp', Date.now());
            }
        }
    }
}

cache

With this option, you can enable/disable content caching. The default value is true. This fulfills read requests by serving cached content, thereby improving the site performance.

logs

Use this settings to set a different path for the logs, and provide the textual or JSON format for logs.

view

Here, you can specify the module, extension, and scaffold settings, along with module-based options such as autoescape and cache (above example is specific for nunjucks; options may vary based on the module).

static

contentstack-express is based on Express.js. This enables us to use the same options that are available for static in Express.js.

assets

contentstack-express creates a URL for each published asset, which you can change from here. Beside, you can also specify the static options of Express.js for the published assets.

storage

Change the location of the storage also with the different providers.

theme

Activate a theme from here. The theme specified here should be one of the themes residing in the ‘themes’ folder.

languages

To configure a language other than the default one on the server, add the language in the format specified below. It requires a valid language code and a relative_url_prefix. You also need to specify that the application is having a separate domain for this particular language.

Example

{
    code: ‘ja-jp’,
    relative_url_prefix: ‘/’,
    host: ‘www.jp.example.com’
}

The above example shows how to add a new localized language (Japanese) on the server. Here, we first specify the language code, and then the relative url prefix. Lastly, we specify the specific domain name for the new language.

Was this article helpful?
^