diff --git a/packages/core/src/server/index.js b/packages/core/src/server/index.js index ea66e763..6642e700 100644 --- a/packages/core/src/server/index.js +++ b/packages/core/src/server/index.js @@ -6,7 +6,6 @@ import controlServer from 'http-shutdown'; import { parse } from 'url'; import debug from 'debug'; import knownPipeline from './knownPipeline'; -import unknownPipeline from './unknownPipeline'; import serverInformation from './serverInformation'; import errorHandler from './errorHandler'; import settings from '../settings'; @@ -46,7 +45,6 @@ function createServer(ezs, serverPort, serverPath, workerId) { }); app.use(metrics(ezs)); app.use(serverInformation(ezs)); - app.use(unknownPipeline(ezs)); app.use(knownPipeline(ezs)); app.use((request, response, next) => { if (request.catched === false) { diff --git a/packages/core/src/server/unknownPipeline.js b/packages/core/src/server/unknownPipeline.js deleted file mode 100644 index 6b00fe02..00000000 --- a/packages/core/src/server/unknownPipeline.js +++ /dev/null @@ -1,54 +0,0 @@ -import debug from 'debug'; -import sizeof from 'object-sizeof'; -import Parameter from '../parameter'; -import errorHandler from './errorHandler'; - -const unknownPipeline = ezs => (request, response, next) => { - - if (request.catched || !request.methodMatch(['POST']) || request.pathName !== '/') { - return next(); - } - request.catched = true; - debug('ezs')(`Create middleware 'unknownPipeline' for ${request.method} ${request.pathName}`); - - const { headers } = request; - response.setHeader('Content-Encoding', headers['content-encoding'] || 'identity'); - const commands = Object.keys(headers) - .filter(headerKey => (headerKey.indexOf('x-command') === 0)) - .map(headerKey => parseInt(headerKey.replace('x-command-', ''), 10)) - .sort((x, y) => x - y) - .map(commandIndex => Parameter.unscramble(headers[`x-command-${commandIndex}`])); - const environment = Object.keys(headers) - .filter(headerKey => (headerKey.indexOf('x-environment') === 0)) - .map(headerKey => headerKey.replace('x-environment-', '')) - .map((environmentKey) => { - const { k, v } = Parameter.unpack(headers[`x-environment-${environmentKey}`]); - return { - [k]: v, - }; - }) - .reduce((prev, cur) => Object.assign(prev, cur), {}); - debug('ezs')( - `PID ${process.pid} will execute ${commands.length} commands with ${sizeof(environment)} of global parameters`, - ); - request - .pipe(ezs.uncompress(headers)) - .pipe(ezs('unpack')) - .pipe(ezs('ungroup')) - .pipe(ezs('delegate', { commands }, environment)) - .pipe(ezs.catch(errorHandler(request, response))) - .pipe(ezs((input, output) => { - if (!response.headersSent) { - response.writeHead(200); - } - return output.send(input); - })) - .pipe(ezs('group')) - .pipe(ezs('pack')) - .pipe(ezs.compress(headers)) - .pipe(response); - request.resume(); - response.once('close', next); -}; - -export default unknownPipeline;