{"id":21339864,"url":"https://github.com/webextensions/express-hard-coded-response","last_synced_at":"2025-03-16T02:41:05.516Z","repository":{"id":57158063,"uuid":"83283258","full_name":"webextensions/express-hard-coded-response","owner":"webextensions","description":"Express middleware to return hard-coded response for requests with url matching specified pattern","archived":false,"fork":false,"pushed_at":"2019-07-19T18:04:09.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-23T14:47:43.458Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webextensions.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-27T07:51:48.000Z","updated_at":"2019-07-19T18:04:11.000Z","dependencies_parsed_at":"2022-09-07T20:33:25.917Z","dependency_job_id":null,"html_url":"https://github.com/webextensions/express-hard-coded-response","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webextensions%2Fexpress-hard-coded-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webextensions%2Fexpress-hard-coded-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webextensions%2Fexpress-hard-coded-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webextensions%2Fexpress-hard-coded-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webextensions","download_url":"https://codeload.github.com/webextensions/express-hard-coded-response/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243817233,"owners_count":20352523,"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-22T00:47:47.385Z","updated_at":"2025-03-16T02:41:05.500Z","avatar_url":"https://github.com/webextensions.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#hardCodedResponse\"\u003ehardCodedResponse(options)\u003c/a\u003e ⇒ \u003ccode\u003e\u003ca href=\"#ExpressMiddleware\"\u003eExpressMiddleware\u003c/a\u003e\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eThis function is an Express JS middleware which would try to match the specified pattern (from an array of MatchCondition objects)\nwith req.originalUrl.\n\u003cbr /\u003e - If no match is found, then the request would just pass through.\n\u003cbr /\u003e - If a match is found, then serve the corresponding file (specified in the MatchCondition object) as its hard-coded response.\n\u003cbr /\u003e\n\u003cbr /\u003e Note: res.locals[\u0026#39;matchedCondition\u0026#39;] is set as per the first-matched-condition\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Typedefs\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#ExpressMiddleware\"\u003eExpressMiddleware\u003c/a\u003e : \u003ccode\u003efunction\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eExpress middleware\u003c/p\u003e\n\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#MatchCondition\"\u003eMatchCondition\u003c/a\u003e : \u003ccode\u003eObject\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eThe condition to be matched (\u003cb\u003e.pattern\u003c/b\u003e is used for match with request and other attributes are used for response)\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"hardCodedResponse\"\u003e\u003c/a\u003e\n\n## hardCodedResponse(options) ⇒ \u003ccode\u003e[ExpressMiddleware](#ExpressMiddleware)\u003c/code\u003e\nThis function is an Express JS middleware which would try to match the specified pattern (from an array of MatchCondition objects)\nwith req.originalUrl.\n\u003cbr /\u003e - If no match is found, then the request would just pass through.\n\u003cbr /\u003e - If a match is found, then serve the corresponding file (specified in the MatchCondition object) as its hard-coded response.\n\u003cbr /\u003e\n\u003cbr /\u003e Note: res.locals['matchedCondition'] is set as per the first-matched-condition\n\n**Kind**: global function  \n**Returns**: \u003ccode\u003e[ExpressMiddleware](#ExpressMiddleware)\u003c/code\u003e - Express middleware  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| options | \u003ccode\u003eObject\u003c/code\u003e |  |  |\n| [options.conditions] | \u003ccode\u003e[Array.\u0026lt;MatchCondition\u0026gt;](#MatchCondition)\u003c/code\u003e |  | Array of conditions which would be used for matching with req.originalUrl                                                        \u003cbr /\u003e A \u003cb\u003efalsy-value\u003c/b\u003e (or empty array) would make this function call effectively empty and the request would pass-through |\n| [options.verbose] | \u003ccode\u003eBoolean\u003c/code\u003e | \u003ccode\u003efalse\u003c/code\u003e | \u003cb\u003etruthy-value\u003c/b\u003e to log each matched URL and corresponding pattern |\n| [options.baseDir] | \u003ccode\u003eObject\u003c/code\u003e | \u003ccode\u003e\u0026quot;\u0026lt;empty-string\u0026gt;\u0026quot;\u003c/code\u003e | Base directory for the relative paths |\n| [options.debugNote] | \u003ccode\u003eObject\u003c/code\u003e | \u003ccode\u003e\u0026quot;This is a hard-coded response intended for debugging purposes only\u0026quot;\u003c/code\u003e | Debug note to be added as HTTP header (and JSON property if MatchCondition says .type is 'json')                                                                                                             \u003cbr /\u003e - If responseText \u0026 responseFile are not provided in MatchCondition, then debugNote is used as the response                                                                                                             \u003cbr /\u003e - Set it to \u003cb\u003efalse\u003c/b\u003e to disable it |\n| [options.console] | \u003ccode\u003eObject\u003c/code\u003e | \u003ccode\u003econsole\u003c/code\u003e | A \u003cb\u003elogging/console object\u003c/b\u003e, which supports .log() and .warn() |\n\n\u003ca name=\"ExpressMiddleware\"\u003e\u003c/a\u003e\n\n## ExpressMiddleware : \u003ccode\u003efunction\u003c/code\u003e\nExpress middleware\n\n**Kind**: global typedef  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| req | \u003ccode\u003eObject\u003c/code\u003e | Request object |\n| res | \u003ccode\u003eObject\u003c/code\u003e | Response object |\n| next | \u003ccode\u003efunction\u003c/code\u003e | Next function |\n\n\u003ca name=\"MatchCondition\"\u003e\u003c/a\u003e\n\n## MatchCondition : \u003ccode\u003eObject\u003c/code\u003e\nThe condition to be matched (\u003cb\u003e.pattern\u003c/b\u003e is used for match with request and other attributes are used for response)\n\n**Kind**: global typedef  \n**Properties**\n\n| Name | Type | Default | Description |\n| --- | --- | --- | --- |\n| pattern | \u003ccode\u003eString\u003c/code\u003e |  | \u003cb\u003e\"none\"\u003c/b\u003e or \u003cb\u003efalsy-value\u003c/b\u003e would match none                                               \u003cbr /\u003e \u003cb\u003e\"*\"\u003c/b\u003e or \u003cb\u003e\"all\"\u003c/b\u003e would match all                                               \u003cbr /\u003e \u003cb\u003e\"\u0026lt;any-other-pattern\u0026gt;\"\u003c/b\u003e would be searched as plain string anywhere in the req.originalUrl |\n| status | \u003ccode\u003eString\u003c/code\u003e | \u003ccode\u003e200\u003c/code\u003e | Response status |\n| type | \u003ccode\u003eString\u003c/code\u003e |  | Type of response (currently supporting 'json')                                               \u003cbr /\u003e                                               \u003cbr /\u003e \u003cb\u003eIf 'json' is used:\u003c/b\u003e                                               \u003cbr /\u003e - \u003cb\u003eresponseFile\u003c/b\u003e's contents would be read as commented-json (CJSON) and the commentes would be stripped-off.                                               \u003cbr /\u003e - 'Content-Type' header is set as 'application/json; charset=utf-8' by default, unless overridden using \u003cb\u003econtentType\u003c/b\u003e option.                                               \u003cbr /\u003e - \u003cb\u003edebugNote\u003c/b\u003e would be added as a property to the JSON response (this can be overwritten through the options when setting up the middleware). |\n| contentType | \u003ccode\u003eString\u003c/code\u003e |  | 'Content-Type' header |\n| responseText | \u003ccode\u003eString\u003c/code\u003e |  | The text to be used as the hard-coded response (responseText has more priority than responseFile) |\n| responseFile | \u003ccode\u003eString\u003c/code\u003e |  | The file to be used as the hard-coded response (responseText has more priority than responseFile) |\n| Any-other-object-properties | \u003ccode\u003e\\*\u003c/code\u003e |  | Any other object properties (these might be accessed after match from res.locals['matchedCondition']) |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebextensions%2Fexpress-hard-coded-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebextensions%2Fexpress-hard-coded-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebextensions%2Fexpress-hard-coded-response/lists"}