npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-hard-coded-response

v0.1.5

Published

Express middleware to return hard-coded response for requests with url matching specified pattern

Downloads

6,106

Readme

Functions

Typedefs

hardCodedResponse(options) ⇒ ExpressMiddleware

This function is an Express JS middleware which would try to match the specified pattern (from an array of MatchCondition objects) with req.originalUrl. - If no match is found, then the request would just pass through. - If a match is found, then serve the corresponding file (specified in the MatchCondition object) as its hard-coded response. Note: res.locals['matchedCondition'] is set as per the first-matched-condition

Kind: global function
Returns: ExpressMiddleware - Express middleware

| Param | Type | Default | Description | | --- | --- | --- | --- | | options | Object | | | | [options.conditions] | Array.<MatchCondition> | | Array of conditions which would be used for matching with req.originalUrl A falsy-value (or empty array) would make this function call effectively empty and the request would pass-through | | [options.verbose] | Boolean | false | truthy-value to log each matched URL and corresponding pattern | | [options.baseDir] | Object | "<empty-string>" | Base directory for the relative paths | | [options.debugNote] | Object | "This is a hard-coded response intended for debugging purposes only" | Debug note to be added as HTTP header (and JSON property if MatchCondition says .type is 'json') - If responseText & responseFile are not provided in MatchCondition, then debugNote is used as the response - Set it to false to disable it | | [options.console] | Object | console | A logging/console object, which supports .log() and .warn() |

ExpressMiddleware : function

Express middleware

Kind: global typedef

| Param | Type | Description | | --- | --- | --- | | req | Object | Request object | | res | Object | Response object | | next | function | Next function |

MatchCondition : Object

The condition to be matched (.pattern is used for match with request and other attributes are used for response)

Kind: global typedef
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | pattern | String | | "none" or falsy-value would match none "*" or "all" would match all "<any-other-pattern>" would be searched as plain string anywhere in the req.originalUrl | | status | String | 200 | Response status | | type | String | | Type of response (currently supporting 'json') If 'json' is used: - responseFile's contents would be read as commented-json (CJSON) and the commentes would be stripped-off. - 'Content-Type' header is set as 'application/json; charset=utf-8' by default, unless overridden using contentType option. - debugNote would be added as a property to the JSON response (this can be overwritten through the options when setting up the middleware). | | contentType | String | | 'Content-Type' header | | responseText | String | | The text to be used as the hard-coded response (responseText has more priority than responseFile) | | responseFile | String | | The file to be used as the hard-coded response (responseText has more priority than responseFile) | | Any-other-object-properties | * | | Any other object properties (these might be accessed after match from res.locals['matchedCondition']) |