enonic / lib-nextxp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lib-nextxp

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.


Usage / install in XP project:

  1. Add to XP project's build.gradle:

    dependencies {
        include 'com.enonic.lib:lib-nextxp:<version>'
    }

    For currently available <version>, see the enonic public repo.


  2. 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);
    }

Configure frontend server URL

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!


Lib development

Local build:

./gradlew build

Local publish:

./gradlew publishToMavenLocal

Publish:

./gradlew publish

Issues:

https://github.com/enonic/lib-nextxp/issues/

About

License:Apache License 2.0


Languages

Language:JavaScript 97.4%Language:Java 2.6%