mirror of
https://github.com/wassname/talk.git
synced 2026-08-17 11:27:52 +08:00
fixed import cycle
This commit is contained in:
+3
-2
@@ -5,7 +5,8 @@ const merge = require('lodash/merge');
|
||||
const errors = require('../errors');
|
||||
|
||||
// Graph
|
||||
const subscriptions = require('./subscriptions');
|
||||
const { getBroker } = require('./subscriptions/broker');
|
||||
const { getPubsub } = require('./subscriptions/pubsub');
|
||||
const resolvers = require('./resolvers');
|
||||
const mutators = require('./mutators');
|
||||
const loaders = require('./loaders');
|
||||
@@ -85,7 +86,7 @@ const defaultConnectors = {
|
||||
Wordlist,
|
||||
},
|
||||
graph: {
|
||||
subscriptions,
|
||||
subscriptions: { getBroker, getPubsub },
|
||||
resolvers,
|
||||
mutators,
|
||||
loaders,
|
||||
|
||||
@@ -2,7 +2,6 @@ const { SubscriptionManager } = require('graphql-subscriptions');
|
||||
const { SubscriptionServer } = require('subscriptions-transport-ws');
|
||||
const debug = require('debug')('talk:graph:subscriptions');
|
||||
|
||||
const { getBroker } = require('./broker');
|
||||
const { getPubsub } = require('./pubsub');
|
||||
const schema = require('../schema');
|
||||
const Context = require('../context');
|
||||
@@ -116,6 +115,4 @@ const createSubscriptionManager = server =>
|
||||
|
||||
module.exports = {
|
||||
createSubscriptionManager,
|
||||
getBroker,
|
||||
getPubsub,
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const { passport } = require('../services/passport');
|
||||
const Context = require('../graph/context');
|
||||
const debug = require('debug')('talk:middleware:authentication');
|
||||
|
||||
const authentication = (req, res, next) =>
|
||||
@@ -23,9 +22,6 @@ const authentication = (req, res, next) =>
|
||||
debug('user was not on request');
|
||||
}
|
||||
|
||||
// Attach a new context to the request.
|
||||
req.context = new Context(req);
|
||||
|
||||
next();
|
||||
}
|
||||
)(req, res, next);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const Context = require('../graph/context');
|
||||
|
||||
// Attach a new context to the request.
|
||||
module.exports = (req, res, next) => {
|
||||
req.context = new Context(req);
|
||||
|
||||
next();
|
||||
};
|
||||
+5
-1
@@ -13,6 +13,7 @@ const staticMiddleware = require('express-static-gzip');
|
||||
const { DISABLE_STATIC_SERVER } = require('../config');
|
||||
const { passport } = require('../services/passport');
|
||||
const { MOUNT_PATH } = require('../url');
|
||||
const context = require('../middleware/context');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -100,9 +101,12 @@ plugins.get('server', 'passport').forEach(plugin => {
|
||||
// Setup the PassportJS Middleware.
|
||||
router.use(passport.initialize());
|
||||
|
||||
// Setup the Graph Context on the router.
|
||||
router.use(authentication, context);
|
||||
|
||||
// Attach the authentication middleware, this will be responsible for decoding
|
||||
// (if present) the JWT on the request.
|
||||
router.use('/api', authentication, require('./api'));
|
||||
router.use('/api', require('./api'));
|
||||
|
||||
//==============================================================================
|
||||
// DEVELOPMENT ROUTES
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
const express = require('express');
|
||||
const debug = require('debug')('talk:routes:plugins');
|
||||
const plugins = require('../services/plugins');
|
||||
const { connectors } = require('../graph');
|
||||
const { set } = require('lodash');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Mount the connectors on the router.
|
||||
router.use((req, res, next) => {
|
||||
set(req, 'talk.connectors', connectors);
|
||||
next();
|
||||
});
|
||||
|
||||
// Inject server route plugins.
|
||||
plugins.get('server', 'router').forEach(plugin => {
|
||||
debug(`added plugin '${plugin.plugin.name}'`);
|
||||
|
||||
Reference in New Issue
Block a user