refactor: request.(socket|page)

This commit is contained in:
cha0s 2021-01-24 11:28:10 -06:00
parent 9cb130d776
commit 7a47af1c37
6 changed files with 11 additions and 7 deletions

View File

@ -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) => {

View File

@ -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));

View File

@ -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),

View File

@ -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();
},

View File

@ -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()');

View File

@ -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()');