From 7a47af1c378f1fb50a53f5c4e4ca8b0f56b209fa Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 24 Jan 2021 11:28:10 -0600 Subject: [PATCH] refactor: request.(socket|page) --- packages/governor/src/server.js | 4 ++-- packages/http/src/http.js | 5 ++++- packages/http/src/server.js | 3 ++- packages/redis/src/session/server.js | 2 +- packages/user/src/server.js | 2 +- packages/user/src/session/server.js | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/governor/src/server.js b/packages/governor/src/server.js index b061bf5..1a3e62a 100644 --- a/packages/governor/src/server.js +++ b/packages/governor/src/server.js @@ -25,10 +25,10 @@ export default { '@latus/db/server/models': gatherWithLatus( require.context('./models', false, /\.js$/), ), - '@latus/http/server/request': (latus) => { + '@latus/http/server/request.page': (latus) => { const {config: {'@latus/governor/server': {http}}} = latus; const limiter = createLimiter(latus, { - keyPrefix: '@latus/http/server/request', + keyPrefix: '@latus/http/server/request.page', ...http, }); return async (req, res, next) => { diff --git a/packages/http/src/http.js b/packages/http/src/http.js index 27885eb..cbc4753 100644 --- a/packages/http/src/http.js +++ b/packages/http/src/http.js @@ -31,8 +31,11 @@ export const createHttpServer = async (latus) => { const httpServer = createServer(app); latus.set('%http', httpServer); httpServer.app = app; + app.use((req, res, next) => { + latus.invokeMiddleware('@latus/http/server/request.socket', req, res, next); + }); const requestMiddleware = (req, res, next) => { - latus.invokeMiddleware('@latus/http/server/request', req, res, next); + latus.invokeMiddleware('@latus/http/server/request.page', req, res, next); }; const routes = arrayFlatten(latus.invokeFlat('@latus/http/routes')); routes.forEach(({method, path, handler}) => app[method](path, requestMiddleware, handler)); diff --git a/packages/http/src/server.js b/packages/http/src/server.js index 5301c81..0f7b168 100644 --- a/packages/http/src/server.js +++ b/packages/http/src/server.js @@ -40,7 +40,8 @@ export default { devPublic: undefined, host: '0.0.0.0', port: 32340, - request: [], + 'request.page': [], + 'request.socket': [], trust: false, }), '@latus/core/server/up': (latus) => createHttpServer(latus), diff --git a/packages/redis/src/session/server.js b/packages/redis/src/session/server.js index 4d8e954..35e059e 100644 --- a/packages/redis/src/session/server.js +++ b/packages/redis/src/session/server.js @@ -26,7 +26,7 @@ const adapterIntoReq = (path, adapter, req) => { export default { hooks: { - '@latus/http/server/request': ({config: {'%redisAdapter': adapter}}) => (req, res, next) => { + '@latus/http/server/request.socket': ({config: {'%redisAdapter': adapter}}) => (req, res, next) => { adapterIntoReq('http', adapter, req); next(); }, diff --git a/packages/user/src/server.js b/packages/user/src/server.js index e8ccfb5..ff60f67 100644 --- a/packages/user/src/server.js +++ b/packages/user/src/server.js @@ -22,7 +22,7 @@ export default { '@latus/db/server/models': gatherWithLatus( require.context('./models', false, /\.js$/), ), - '@latus/http/server/request': (latus) => (req, res, next) => { + '@latus/http/server/request.page': (latus) => (req, res, next) => { debug('@latus/http/server/request: passport.initialize()'); passport.initialize()(req, res, () => { debug('@latus/http/server/request: passport.session()'); diff --git a/packages/user/src/session/server.js b/packages/user/src/session/server.js index b753093..0e5ef83 100644 --- a/packages/user/src/session/server.js +++ b/packages/user/src/session/server.js @@ -15,7 +15,7 @@ export default { ...latus.invokeReduce('@latus/user/session'), })); }, - '@latus/http/server/request': (latus) => { + '@latus/http/server/request.page': (latus) => { const urle = express.urlencoded({extended: true}); return (req, res, next) => { debug('@latus/http/server/request: express.urlencoded()');