From 89b8aa2f6c4d31880a0dc8750d98564f4310443e Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 19 Jan 2021 11:16:12 -0600 Subject: [PATCH] refactor(security): core --- app/latus.default.yml | 3 ++- packages/core/src/server.js | 6 ++---- packages/core/src/start.js | 2 +- packages/db/src/server.js | 2 +- packages/http/src/server.js | 2 +- packages/redis/src/server.js | 2 +- packages/repl/src/server.js | 2 +- packages/socket/src/client/index.js | 2 +- packages/user/src/local/server.js | 2 +- packages/user/src/server.js | 2 +- packages/user/src/session/server.js | 2 +- 11 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/latus.default.yml b/app/latus.default.yml index d5ae9bb..4111ffc 100644 --- a/app/latus.default.yml +++ b/app/latus.default.yml @@ -1,4 +1,5 @@ -'@latus/core': { +'@latus/core': {} +'@latus/core/server': { up: [ '@latus/db/server', '@latus/redis/server', diff --git a/packages/core/src/server.js b/packages/core/src/server.js index 7c801cb..67d19b2 100644 --- a/packages/core/src/server.js +++ b/packages/core/src/server.js @@ -2,10 +2,8 @@ export {default as appdata} from './appdata'; export default { hooks: { - '@latus/http/plugins': (req, {config: {'@latus/core': {id}}}) => ({ - '@latus/core/client': { - id, - }, + '@latus/core/config': () => ({ + up: [], }), '@latus/repl/context': (latus) => ({latus}), }, diff --git a/packages/core/src/start.js b/packages/core/src/start.js index 5f86b41..d5f0eca 100644 --- a/packages/core/src/start.js +++ b/packages/core/src/start.js @@ -7,7 +7,7 @@ process.stdout.write('Latus starting...\n'); try { await Promise.all(latus.invokeFlat('@latus/core/starting')); await Promise.all(latus.invokeFlat('@latus/core/started')); - await latus.invokeSequential('@latus/core/up'); + await latus.invokeSequential('@latus/core/server/up'); // eslint-disable-next-line no-console console.log('Latus up!'); } diff --git a/packages/db/src/server.js b/packages/db/src/server.js index f4cb72f..c0e66a7 100644 --- a/packages/db/src/server.js +++ b/packages/db/src/server.js @@ -31,7 +31,7 @@ export default { }, )); }, - '@latus/core/up': (latus) => { + '@latus/core/server/up': (latus) => { const {config: {'@latus/db/server': {docker}}} = latus; if ('production' !== NODE_ENV && docker) { createDockerContainer(latus); diff --git a/packages/http/src/server.js b/packages/http/src/server.js index 22884f1..13176cd 100644 --- a/packages/http/src/server.js +++ b/packages/http/src/server.js @@ -43,7 +43,7 @@ export default { request: [], trust: false, }), - '@latus/core/up': (latus) => createHttpServer(latus), + '@latus/core/server/up': (latus) => createHttpServer(latus), '@latus/repl/context': (latus) => ({ httpServer: latus.config['%http'], }), diff --git a/packages/redis/src/server.js b/packages/redis/src/server.js index 0f103aa..b1871b6 100644 --- a/packages/redis/src/server.js +++ b/packages/redis/src/server.js @@ -36,7 +36,7 @@ export default { host: '127.0.0.1', port: 6380, }), - '@latus/core/up': (latus) => { + '@latus/core/server/up': (latus) => { const {config: {'@latus/redis/server': {docker}}} = latus; return 'production' !== NODE_ENV && docker ? createDockerContainer(latus) : undefined; }, diff --git a/packages/repl/src/server.js b/packages/repl/src/server.js index 84a76c1..9d5b887 100644 --- a/packages/repl/src/server.js +++ b/packages/repl/src/server.js @@ -2,6 +2,6 @@ import {createReplServer} from './repl'; export default { hooks: { - '@latus/core/up': (latus) => createReplServer(latus), + '@latus/core/server/up': (latus) => createReplServer(latus), }, }; diff --git a/packages/socket/src/client/index.js b/packages/socket/src/client/index.js index c07aa79..9c3551d 100644 --- a/packages/socket/src/client/index.js +++ b/packages/socket/src/client/index.js @@ -8,7 +8,7 @@ export default { socket.connect(); socket.listen(); }, - '@latus/socket/client': ({config: {'@latus/core/client': {id}}}) => ({ + '@latus/socket/client': ({config: {'@latus/core': {id}}}) => ({ cors: { origin: false, }, diff --git a/packages/user/src/local/server.js b/packages/user/src/local/server.js index bd5d25c..e8fd0ff 100644 --- a/packages/user/src/local/server.js +++ b/packages/user/src/local/server.js @@ -10,7 +10,7 @@ export default { successRedirect: '/', failureRedirect: '/', }), - '@latus/core/up': (latus) => { + '@latus/core/server/up': (latus) => { passport.use(new LocalStrategy( {usernameField: 'email'}, async (email, password, fn) => { diff --git a/packages/user/src/server.js b/packages/user/src/server.js index 253ed7e..a9898e8 100644 --- a/packages/user/src/server.js +++ b/packages/user/src/server.js @@ -7,7 +7,7 @@ const debug = D('@latus/user/passport'); export default { hooks: { - '@latus/core/up': (latus) => { + '@latus/core/server/up': (latus) => { passport.serializeUser((user, fn) => fn(null, user.id)); passport.deserializeUser(async (id, fn) => { const {User} = latus.get('%models.fromName'); diff --git a/packages/user/src/session/server.js b/packages/user/src/session/server.js index 2e6ab5d..d331029 100644 --- a/packages/user/src/session/server.js +++ b/packages/user/src/session/server.js @@ -6,7 +6,7 @@ const debug = D('@latus/user/session'); export default { hooks: { - '@latus/core/up': (latus) => { + '@latus/core/server/up': (latus) => { // eslint-disable-next-line no-param-reassign latus.config['%session'] = expressSession({ resave: false,