OpenPaaS Documentation logo OpenPaaS Documentation

Table of contents

Overview

The OpenPaaS modules are the most powerfull way to add features into the OpenPaaS Enterprise Social Network. With modules, you can:

Let’s code

In the modules folder of your OpenPaaS ESN installation, create a new folder com.example.module. Inside this folder, create a new file index.js, containing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const express = require('express');
const AwesomeModule = require('awesome-module');
const Dependency = AwesomeModule.AwesomeModuleDependency;

const esnModule = new AwesomeModule('com.example.module', {
  dependencies: [
    new Dependency(Dependency.TYPE_NAME, 'linagora.esn.core.webserver.wrapper', 'webserver-wrapper')
  ],
  states: {
    deploy: function(dependencies, callback) {
      const webserver = dependencies('webserver-wrapper');
      const router = express.Router();

      router.get('/', (req,res) => {
        res.status(200).json({ok: true});
      });

      webserver.addApp('example', router);
      callback();
    }
  }
});

module.exports = esnModule;

Now, open the configuration file config/default.dev.json, and add the new modules at the end of your modules list:

1
2
3
4
5
6
7
{
  ...
  "modules": [
    ...,
    "com.example.module"
  ]
}

Restart your ESN server, using the grunt dev command. You can now query your new endpoint :

$ curl http://localhost:8080/example/
{"ok": true}

Let’s now dig deeper in the OpenPaaS modules features.