How to use router lib


#1

Enonic version: 7.0.3
OS: Linux Mint 19.3

The router lib not works for me. This is the example that I use to test:
I added the dependency in build.gradle:

include "com.enonic.lib:lib-router:2.1.0"

:spiral_notepad:com.enonic.xp.web.vhost.cfg

mapping.app.host = localhost
mapping.app.source = /app
mapping.app.target =  /app
mapping.app.idProvider.system = default

:spiral_notepad:main.js

var router = require('/lib/router')();

// Dispatch all requests to the router.
exports.all = function (req) {
  return router.dispatch(req);
};

// Add a route for the GET method.
router.get('/myroute', function (req) {
  return {
    body: `
      <!DOCTYPE html>
      <html>
        <body>
          <h1>My Example</h1>
        </body>
      </html>
    `
  }
});

When I access the address http://localhost:8080/app/myappname/myroute, the page returns an 404.
What I made wrong?


#2

“/app” has been renamed to “/webapp” in 7.0


#3

Thanks @gri ! :grinning: