chore: flow
This commit is contained in:
parent
6c8ef04f7a
commit
93c1cc60ae
6
build.js
6
build.js
|
@ -6,7 +6,7 @@ const dotenv = require('dotenv');
|
|||
|
||||
const {emitObject, emitString} = require('./compose');
|
||||
|
||||
['.common.env', '.prod.env', '.env'].forEach((filename) => {
|
||||
['.common.env', '.production.env', '.env'].forEach((filename) => {
|
||||
dotenv.config({path: path.join(__dirname, filename)});
|
||||
});
|
||||
|
||||
|
@ -31,7 +31,7 @@ fs.copyFileSync(
|
|||
|
||||
fs.appendFileSync(
|
||||
path.join(distPath, '.env'),
|
||||
fs.readFileSync(path.join(cwd, '.prod.env')),
|
||||
fs.readFileSync(path.join(cwd, '.production.env')),
|
||||
);
|
||||
|
||||
fs.appendFileSync(
|
||||
|
@ -49,7 +49,7 @@ for (const service of services) {
|
|||
spawnSync('docker', [
|
||||
'run',
|
||||
'--env-file', './.common.env',
|
||||
'--env-file', './.prod.env',
|
||||
'--env-file', './.production.env',
|
||||
'--env-file', './.env',
|
||||
|
||||
'-e', 'DEBUG=truss:*',
|
||||
|
|
15
compose.js
15
compose.js
|
@ -18,11 +18,20 @@ exports.emitObject = function(services) {
|
|||
|
||||
for (const service of services) {
|
||||
composeFile.services[service] = emitService(service);
|
||||
const modulePath = `./services/${service}/compose`;
|
||||
try {
|
||||
require(modulePath)(composeFile.services[service]);
|
||||
console.log('compose');
|
||||
}
|
||||
catch (error) {
|
||||
const message = `Cannot find module '${modulePath}'`;
|
||||
if (message !== error.message) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const gatewayPort = process.env.GATEWAY_PORT || 8000;
|
||||
composeFile.services.gateway.ports = [`${gatewayPort}:8000`];
|
||||
|
||||
return composeFile;
|
||||
}
|
||||
|
||||
|
|
5
services/gateway/compose.js
Normal file
5
services/gateway/compose.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
module.exports = (config) => {
|
||||
const gatewayPort = process.env.GATEWAY_PORT || 8000;
|
||||
config.ports = [`${gatewayPort}:8000`];
|
||||
};
|
||||
|
|
@ -49,7 +49,7 @@ ${type}.
|
|||
// hey, listen
|
||||
const httpServer = http.createServer();
|
||||
reduceServiceMap$.then((serviceMap) => {
|
||||
debug(`service map: ${JSON.stringify(serviceMap)}`);
|
||||
debug(`service map: ${JSON.stringify(serviceMap, null, ' ')}`);
|
||||
|
||||
const port = process.env.GATEWAY_PORT || 8000;
|
||||
httpServer.listen(port);
|
||||
|
@ -78,8 +78,12 @@ reduceServiceMap$.then((serviceMap) => {
|
|||
}).catch(console.error);
|
||||
|
||||
function invokeHookFlat(services, hook, args) {
|
||||
debug(`invoking hook flat(${hook}(${JSON.stringify(args)}))...`);
|
||||
debug(`invoking hook flat(${hook}(${JSON.stringify(args, null, ' ')}))...`);
|
||||
|
||||
invokeHookFlatInternal(services, hook, args);
|
||||
}
|
||||
|
||||
function invokeHookFlatInternal(services, hook, args) {
|
||||
const action = {type: 'truss/hook', payload: {hook, args}};
|
||||
return Promise.all(services.map((service) => {
|
||||
return sendActionToService(action, service);
|
||||
|
@ -87,9 +91,9 @@ function invokeHookFlat(services, hook, args) {
|
|||
}
|
||||
|
||||
function invokeHook(services, hook, args) {
|
||||
debug(`invoking hook ${hook}(${JSON.stringify(args)})...`);
|
||||
debug(`invoking hook ${hook}(${JSON.stringify(args, null, ' ')})...`);
|
||||
|
||||
return invokeHookFlat(services, hook, args).then((result) => {
|
||||
return invokeHookFlatInternal(services, hook, args).then((result) => {
|
||||
return result.reduce((l, r, i) => (l[services[i]] = r, l), {});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ module.exports = function(serviceMap, req, res) { parser(req, res, () => {
|
|||
debug(`HTTP ${req.method} ${req.url}`);
|
||||
|
||||
// map to action
|
||||
const action = {payload: {url: req.url}};
|
||||
const action = {type: undefined, payload: {url: req.url}};
|
||||
switch (req.method) {
|
||||
|
||||
case 'POST':
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user