From febe264320030c8e6beee72d03dbae2d8812488b Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 3 Apr 2017 15:31:51 -0600 Subject: [PATCH] Added route support --- plugins.js | 5 ++++- routes/index.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins.js b/plugins.js index c53ed1886..3060008d5 100644 --- a/plugins.js +++ b/plugins.js @@ -122,7 +122,10 @@ class PluginSection { hook(hook) { return this.plugins .filter(({module}) => hook in module) - .map((plugin) => ({plugin, [hook]: module[hook]})); + .map((plugin) => ({ + plugin, + [hook]: plugin.module[hook] + })); } } diff --git a/routes/index.js b/routes/index.js index 58c8f13d7..f6745b1c7 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,7 @@ const express = require('express'); const path = require('path'); +const plugins = require('../services/plugins'); +const debug = require('debug')('talk:routes'); const router = express.Router(); @@ -22,4 +24,12 @@ if (process.env.NODE_ENV !== 'production') { }); } +// Inject server route plugins. +plugins.get('server', 'routes').forEach(({plugin, routes}) => { + debug(`added plugin '${plugin.name}'`); + + // Pass the root router to the plugin to mount it's routes. + routes(router); +}); + module.exports = router;