XP-side proxy that can relay rendering to an external server (using it to render the frontend preview of a content item in content studio).
The lib adds a proxy controller (/lib/nextxp/proxy.js) that requires
a controller mapping in the host app's site.xml (see "
installation" above).
The proxy sends requests to <frontendUrl>/X/Y/Z
, and handles any errors or returns the response so that is rendered as
a preview in
content studio.
-
Add to XP project's build.gradle:
dependencies { include 'com.enonic.lib:lib-nextxp:<version>' }
For currently available
<version>
, see the enonic public repo.
-
Add to XP project's site.xml
<mappings>
section:<mapping controller="/lib/nextxp/proxy.js" order="99"> <pattern>/.*</pattern> </mapping>
This is a controller mapping that matches every url and maps the rendering to this lib's proxy, i.e. external rendering.
Proxy can be invoked directly in page/component controllers as well:
var proxy = require('/lib/nextxp/proxy'); exports.get = function (req) { return proxy.get(req); }
By default, this lib will assume the frontend server can be contacted on http://localhost:3000
.
To configure this, you can add/modify a config file named same as your XP application gradle name (i.e. com.example.myproject.cfg
) with
the following line to <xp-home>/config
folder:
nextjs.url=http://localhost:1234
nextjs.secret=mySecret
Changes to this file are applied immediately!
./gradlew build
./gradlew publishToMavenLocal
./gradlew publish