diff --git a/app/latus.default.yml b/app/latus.default.yml index 415318e..52768c2 100644 --- a/app/latus.default.yml +++ b/app/latus.default.yml @@ -23,6 +23,8 @@ '@latus/socket/client', '@latus/react/client', ], +} +'@latus/http/server': { request: [ '@latus/user/session', '@latus/user/passport', diff --git a/packages/governor/src/server.js b/packages/governor/src/server.js index fe27a13..12723e9 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/request': (latus) => { + '@latus/http/server/request': (latus) => { const {config: {'@latus/governor/server': {http}}} = latus; const limiter = createLimiter(latus, { - keyPrefix: '@latus/http/request', + keyPrefix: '@latus/http/server/request', ...http, }); return async (req, res, next) => { diff --git a/packages/http/.neutrinorc.js b/packages/http/.neutrinorc.js index 9c9a5fa..808b25e 100644 --- a/packages/http/.neutrinorc.js +++ b/packages/http/.neutrinorc.js @@ -3,7 +3,7 @@ const copy = require('@neutrinojs/copy'); module.exports = require('../../config/.neutrinorc'); module.exports.use.push(copy({ - patterns: ['index.js', 'index.ejs', 'tests.js'].map((path) => ({ + patterns: ['entry.js', 'index.ejs', 'tests.js'].map((path) => ({ from: `src/client/${path}`, to: 'client', })).concat(['.neutrinorc.js', 'client-plugins.js', 'webpack.config.js'].map((path) => ({ diff --git a/packages/http/src/build/.neutrinorc.js b/packages/http/src/build/.neutrinorc.js index d6ef459..fdb03a4 100644 --- a/packages/http/src/build/.neutrinorc.js +++ b/packages/http/src/build/.neutrinorc.js @@ -25,7 +25,7 @@ const client = { const root = `${__dirname}/..`; neutrino.options.root = fs.realpathSync(root); neutrino.options.source = 'client'; - neutrino.options.mains.index = 'index'; + neutrino.options.mains.index = 'entry'; neutrino.options.mains.tests = { entry: './client/tests', title: 'Mocha tests', diff --git a/packages/http/src/client/entry.js b/packages/http/src/client/entry.js new file mode 100644 index 0000000..84e3c94 --- /dev/null +++ b/packages/http/src/client/entry.js @@ -0,0 +1,15 @@ +import {Latus} from '@latus/core'; +// eslint-disable-next-line import/no-unresolved +import '@latus/core/virtual'; + +(async () => { + if (!window.$$latus) { + return; + } + const latus = new Latus(window.$$latus); + await Promise.all(latus.invokeFlat('@latus/core/starting')); + await Promise.all(latus.invokeFlat('@latus/core/started')); + await latus.invokeSequential('@latus/http/client/up'); + // eslint-disable-next-line no-console + console.log('Latus up!\n'); +})(); diff --git a/packages/http/src/client/index.js b/packages/http/src/client/index.js index 84e3c94..c40eef6 100644 --- a/packages/http/src/client/index.js +++ b/packages/http/src/client/index.js @@ -1,15 +1,7 @@ -import {Latus} from '@latus/core'; -// eslint-disable-next-line import/no-unresolved -import '@latus/core/virtual'; - -(async () => { - if (!window.$$latus) { - return; - } - const latus = new Latus(window.$$latus); - await Promise.all(latus.invokeFlat('@latus/core/starting')); - await Promise.all(latus.invokeFlat('@latus/core/started')); - await latus.invokeSequential('@latus/http/client/up'); - // eslint-disable-next-line no-console - console.log('Latus up!\n'); -})(); +export default { + hooks: { + '@latus/core/config': () => ({ + up: [], + }), + }, +}; diff --git a/packages/http/src/http.js b/packages/http/src/http.js index e7f707e..4c1b746 100644 --- a/packages/http/src/http.js +++ b/packages/http/src/http.js @@ -17,7 +17,7 @@ const { export const createHttpServer = async (latus) => { const { config: { - '@latus/http': { + '@latus/http/server': { build, devPort, host, @@ -33,7 +33,7 @@ export const createHttpServer = async (latus) => { latus.config['%http'] = httpServer; httpServer.app = app; const requestMiddleware = (req, res, next) => { - latus.invokeMiddleware('@latus/http/request', req, res, next); + latus.invokeMiddleware('@latus/http/server/request', 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/index.js b/packages/http/src/index.js index f2379df..750423b 100644 --- a/packages/http/src/index.js +++ b/packages/http/src/index.js @@ -1,16 +1,7 @@ export default { hooks: { '@latus/core/config': () => ({ - build: 'build/http', - 'client.up': [], - devPort: 32341, - devPublic: undefined, - host: '0.0.0.0', - plugins: [], - port: 32340, - request: [], title: 'Latus', - trust: false, }), }, }; diff --git a/packages/http/src/server.js b/packages/http/src/server.js index 1d56be7..22884f1 100644 --- a/packages/http/src/server.js +++ b/packages/http/src/server.js @@ -7,7 +7,7 @@ export default { '@latus/core/build': (configs, latus) => { const { config: { - '@latus/http': { + '@latus/http/server': { devPort, devPublic, host, @@ -34,10 +34,16 @@ export default { spawn(`${binary} --hot --mode development --config ${config}`, options); } }, - '@latus/core/up': (latus) => createHttpServer(latus), - '@latus/http/plugins': (req, {config: {'@latus/http': {'client.up': up}}}) => ({ - '@latus/http/client': {up}, + '@latus/core/config': () => ({ + build: 'build/http', + devPort: 32341, + devPublic: undefined, + host: '0.0.0.0', + port: 32340, + request: [], + trust: false, }), + '@latus/core/up': (latus) => createHttpServer(latus), '@latus/repl/context': (latus) => ({ httpServer: latus.config['%http'], }), diff --git a/packages/redis/src/session/server.js b/packages/redis/src/session/server.js index 4c874de..b5e23c5 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/request': ({config: {'%redisAdapter': adapter}}) => (req, res, next) => { + '@latus/http/server/request': ({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 5727929..9f0e472 100644 --- a/packages/user/src/server.js +++ b/packages/user/src/server.js @@ -22,10 +22,10 @@ export default { '@latus/db/server/models': gatherWithLatus( require.context('./models', false, /\.js$/), ), - '@latus/http/request': (latus) => (req, res, next) => { - debug('@latus/http/request: passport.initialize()'); + '@latus/http/server/request': (latus) => (req, res, next) => { + debug('@latus/http/server/request: passport.initialize()'); passport.initialize()(req, res, () => { - debug('@latus/http/request: passport.session()'); + debug('@latus/http/server/request: passport.session()'); passport.session()(req, res, () => { if (!req.user) { const {User} = latus.get('%models.fromName'); diff --git a/packages/user/src/session/server.js b/packages/user/src/session/server.js index 6a122d7..97c0471 100644 --- a/packages/user/src/session/server.js +++ b/packages/user/src/session/server.js @@ -16,12 +16,12 @@ export default { ...latus.invokeReduce('@latus/user/session'), }); }, - '@latus/http/request': (latus) => { + '@latus/http/server/request': (latus) => { const urle = express.urlencoded({extended: true}); return (req, res, next) => { - debug('@latus/http/request: express.urlencoded()'); + debug('@latus/http/server/request: express.urlencoded()'); urle(req, res, () => { - debug('@latus/http/request: session()'); + debug('@latus/http/server/request: session()'); latus.config['%session'](req, res, (error) => { if (error) { next(error);