Skip to main content
Platform
Language

Using a custom URI resolver

CE.SDK gives you full control over how URIs should be resolved. To register a custom resolver, use setURIResolver and pass in a function implementing your resolution logic. If a custom resolver is set, any URI requested by the engine is passed through the resolver. The URI your logic returns is then fetched by the engine. The resolved URI is just used for the current request and not stored. If, and only if, no custom resolver is set, the engine performs the default behaviour: absolute paths are unchanged and relative paths are prepended with the value of the basePath setting.

Warning#

Your custom URI resolver must return an absolute path with a scheme.

Explore a full code sample on Stackblitz or view the code on Github.

We can preview the effects of setting a custom URI resolver with the function getAbsoluteURI.

Before setting a custom URI resolver, the default behavior is as before and the given relative path will be prepended with the contents of basePath.

To show that the resolver can be fairly free-form, in this example we register a custom URI resolver that replaces all .jpg images with our company logo. The resolved URI are expected to be absolute.

Note: you can still access the default URI resolver by calling defaultURIResolver(relativePath).

Given the same path as earlier, the custom resolver transforms it as specified. Note that after a custom resolver is set, relative paths that the resolver does not transform remain unmodified.

To remove a previously set custom resolver, call the function with a null value. The URI resolution is now back to the default behavior.