Skip to content

Very short example of how to use connect-prism as a recording proxy

License

Notifications You must be signed in to change notification settings

eitland/prism-proxy-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prism-proxy-example

This is intended to be a very short example of how to use connect-prism as a recording proxy.

Why would I use this

Examples of when you might consider using something like this:

  • you are developing against a slow or unreliable server

  • you frequently want to work offline but cannot since you rely on a server

  • you are developing against a moving target

  • you want to test agains specific responses that are hard to recreate on the fly

How to use this example

Prerequisites

  • git

  • node

  • npm or yarn

Install dependencies

Either: Install dependencies using yarn (preferred)

cd prism-proxy-example
yarn install

Or: Install dependencies using npm

cd prism-proxy-example
npm install

Configure

Open the index.js file:

var connect = require('connect');
var prism = require('connect-prism');
var http = require('http');

prism.create({
  name: 'api',
  context: '/api',
  host: 'localhost', //(1)
  port: 8080, //(2)
  mode: 'mockrecord' //(3)
});

var app = connect()
  .use(prism.middleware)

http.createServer(app).listen(3000); //(4)
  1. host: the server name of the server you normally would connect to

  2. port: the port number on the server you would normally connect to

  3. mode: see https://github.com/seglo/connect-prism for explanations

  4. listen(…​): here you can specify the port number you want your proxy to listen to

Start it

yarn start

What to expect

Given the configuration listed above expect the server * to start at localhost:3000 * to answer calls by trying to look up a recorded response if no recorded responose where found: proxy the request to localhost:8080 and record the response * to store recorder mocks in mocks/api

About

Very short example of how to use connect-prism as a recording proxy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published