New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

connect-mockery

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-mockery

Connect middleware for simple resource mocking in single page apps

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
5
150%
Maintainers
1
Weekly downloads
 
Created
Source

connect-mockery Build Status

Connect middleware for simple resource mocking in single page apps

Getting Started

Install the module with: npm install connect-mockery

Documentation

Connect-Mockery lets you put some variance in your mock data.

This module exports a single function which takes a config object and returns a function to used as connect/express middleware.

The middleware looks at incoming requests, sees if they match a folder in your mocks mockBase and if so the server will respond with one of the files it sees there. Which file? Connect Mockery will cycle through them so subsequent requests can get different responses.

Suppose I have this folder structure in my app root:

/mock
  /users
    user-001.json
    user-002.json
    user-003.json

The first request to /mock/users will get user-001.json, the next request gets user-002.json and so on. Connect Mockery will reset the cycling process on page reloads (in particular on requests to '/').

Use the appBase option to set you app base directory (defaults to process.cwd() + '/app')

Use the mockBase option to set your mocks base directory (defaults to /mock').

Use the cleanCacheOnRefresh option to enable/disable cycle resetting (defaults to true).

Examples

var mockery = require('connect-mockery');

var opts = {
    appBase: __dirname + '/app',
    mockBase: '/mock',
    cleanCacheOnRefresh: true
  };

var app = connect()
  .use(mockery(opts))
  // ...
  .use(function(req, res) {
    res.end('hello world\n');
  });

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

  • v0.1.0 Initial release

License

Copyright (c) 2014 iVantage Health Analytics, Inc. Licensed under the MIT license.

FAQs

Package last updated on 05 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts