mirror of
https://github.com/wassname/talk.git
synced 2026-07-03 03:46:48 +08:00
Merge pull request #1222 from coralproject/app-plugin
Added support for app plugin hook
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
const express = require('express');
|
||||
const morgan = require('morgan');
|
||||
const path = require('path');
|
||||
const uuid = require('uuid');
|
||||
const merge = require('lodash/merge');
|
||||
const helmet = require('helmet');
|
||||
const plugins = require('./services/plugins');
|
||||
const compression = require('compression');
|
||||
const {HELMET_CONFIGURATION} = require('./config');
|
||||
const {MOUNT_PATH} = require('./url');
|
||||
@@ -11,6 +13,25 @@ const debug = require('debug')('talk:app');
|
||||
|
||||
const app = express();
|
||||
|
||||
// Request Identity Middleware
|
||||
app.use((req, res, next) => {
|
||||
req.id = uuid.v4();
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
//==============================================================================
|
||||
// PLUGIN PRE APPLICATION MIDDLEWARE
|
||||
//==============================================================================
|
||||
|
||||
// Inject server route plugins.
|
||||
plugins.get('server', 'app').forEach(({plugin, app: callback}) => {
|
||||
debug(`added plugin '${plugin.name}'`);
|
||||
|
||||
// Pass the app to the plugin to mount it's routes.
|
||||
callback(app);
|
||||
});
|
||||
|
||||
//==============================================================================
|
||||
// APPLICATION WIDE MIDDLEWARE
|
||||
//==============================================================================
|
||||
|
||||
+10
-6
@@ -42,14 +42,15 @@ const decorateContextPlugins = (context, contextPlugins) => {
|
||||
* Stores the request context.
|
||||
*/
|
||||
class Context {
|
||||
constructor({user = null}) {
|
||||
constructor(parent) {
|
||||
|
||||
// Generate a new context id for the request.
|
||||
this.id = uuid.v4();
|
||||
// Generate a new context id for the request if the parent doesn't provide
|
||||
// one.
|
||||
this.id = parent.id || uuid.v4();
|
||||
|
||||
// Load the current logged in user to `user`, otherwise this'll be null.
|
||||
if (user) {
|
||||
this.user = user;
|
||||
// Load the current logged in user to `user`, otherwise this will be null.
|
||||
if (parent.user) {
|
||||
this.user = parent.user;
|
||||
}
|
||||
|
||||
// Attach the connectors.
|
||||
@@ -66,6 +67,9 @@ class Context {
|
||||
|
||||
// Bind the publish/subscribe to the context.
|
||||
this.pubsub = pubsub.getClient();
|
||||
|
||||
// Bind the parent context.
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -55,7 +55,8 @@ const hookSchemas = {
|
||||
loaders: Joi.func().maxArity(1),
|
||||
mutators: Joi.func().maxArity(1),
|
||||
resolvers: Joi.object().pattern(/\w/, Joi.object().pattern(/(?:__resolveType|\w+)/, Joi.func())),
|
||||
typeDefs: Joi.string()
|
||||
typeDefs: Joi.string(),
|
||||
schemaLevelResolveFunction: Joi.func(),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -172,7 +173,7 @@ class PluginSection {
|
||||
if (this.required) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.required = true;
|
||||
this.plugins.forEach((plugin) => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user