{"id":19513036,"url":"https://github.com/invrs/mezzo","last_synced_at":"2025-07-08T04:41:54.133Z","repository":{"id":57153714,"uuid":"39704770","full_name":"invrs/mezzo","owner":"invrs","description":"Abstract anything into middleware","archived":false,"fork":false,"pushed_at":"2015-09-21T04:29:18.000Z","size":152,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-09T11:04:34.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/invrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-25T22:21:10.000Z","updated_at":"2015-07-27T02:25:56.000Z","dependencies_parsed_at":"2022-09-07T06:01:06.972Z","dependency_job_id":null,"html_url":"https://github.com/invrs/mezzo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Fmezzo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Fmezzo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Fmezzo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invrs%2Fmezzo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/invrs","download_url":"https://codeload.github.com/invrs/mezzo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240762325,"owners_count":19853460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T23:28:32.986Z","updated_at":"2025-02-25T23:22:15.627Z","avatar_url":"https://github.com/invrs.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mezzo\n\n[![Build Status](https://travis-ci.org/invrs/mezzo.svg?branch=master)](https://travis-ci.org/invrs/mezzo)\n\nAbstract anything into middleware.\n\n## The future\n\nWhat if you could use middleware for things other than an HTTP request?\n\nThings like:\n\n* configuring a web server\n* building your client assets\n* extending component functionality\n* DRYing up shared project functionality\n\n### Example\n\nFrom the **[paradiso](https://github.com/invrs/paradiso)** web framework:\n\n```coffee\n# Start the web server\n#\nroutes  = require \"./routes\"\nserver  = require \"paradiso-server\"\nexpress = require \"paradiso-server-express\"\n\nserver routes, express\n  port:   9000\n  static: \"public\"\n```\n\n### Goals\n\n* Abstract library-specific code into small, reusable, and testable middleware.\n* Maintain a similar interface for libraries that do the same thing.\n* (Change out libraries without changing app code.)\n* Piece together and configure middleware easily.\n\n### Configuring middleware\n\nIf you only pass options to an adapter, it **does not** run the middleware chain.\n\n```coffee\nbuild option: true\n```\n\nHowever, it does save the options for a later execution:\n\n```coffee\nbuild option: true\nbuild()  # @options.option is still true\n```\n\n### Run the workflow\n\nIf you pass an adapter or nothing at all, the middleware chain **does** run:\n\n```coffee\nbuild()\nbuild browserify, coffeeify\nbuild browserify, coffeeify, option: true\n```\n\n## Write middleware\n\nSkeleton implementation of a mezzo middleware:\n\n```coffee\nmezzo = require \"mezzo\"\n\nmodule.exports = mezzo class\n  constructor: ({\n    @adapters  # array of adapters in order of execution\n    @options   # any options passed as a parameter (merged)\n    @index     # index of this adapter in `@adapters`\n  }) -\u003e\n\n  run: ({ env, next }) -\u003e next env\n```\n\n### Put it all together\n\n```coffee\nmezzo = require \"mezzo\"\n\n# Build adapters\n#\na = mezzo class\n  constructor: ({ @options }) -\u003e\n\n  run: ({ env, next }) -\u003e\n    console.log \"a @options\", @options\n  \tenv.a_run = true\n  \tnext()\n\nb = mezzo class\n  run: ({ env, next }) -\u003e\n  \tconsole.log \"b\"\n  \tnext b_run: true\n\nc = mezzo class\n  run: ({ env, next }) -\u003e\n  \tenv.c_run = true\n  \tconsole.log \"c env\", env\n  \tnext()\n\n# Set options\n#\na opt: true\n\n# Execute middleware chain\n#\na b, c, opt2: true\n\n# Output:\n#\n#   a @options { opt: true, opt2: true }\n#   b\n#   c env { a_run: true, b_run: true, c_run: true }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvrs%2Fmezzo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finvrs%2Fmezzo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvrs%2Fmezzo/lists"}