Git Product home page Git Product logo

server-with-benefits's Introduction

server-with-benefits

A static Node.js file web server with options for proxing requests and delaying/mocking responses. Useful for web development.

Installation

$ npm install -g server-with-benefits

Then, to setup your server(s), edit _swbConfig.json that comes with the package and rename it to swbConfig.json.
You can place this file anywhere you like, but make sure you then start the server (see Usage) from the directory where it's placed.
Alternatively (and preferably), you can avoid this restriction by setting an environment variable named SWB_CONF_FILE with the file's full path as its value (e.g. SWB_CONF_FILE=C:\dev\swbConfig.json).

The configuration file should be of the following format:

{
	"servers": [
		{
			"srcDir": "enter/your/path/here", // path to your local server root source directory
			"paths": { // (OPTIONAL) define routes for specific paths, relative to the 'srcDir'
				"/": "/src", // i.e. http://<your_host_name>/ -> <srcDir>/src
				"/lib": "/lib" // i.e. http://<your_host_name>/lib -> <srcDir>/lib
			},
			"port": 80, // the server listen port (default 80)
			"proxy": { // (OPTIONAL) A proxy to a remote server for some path patterns
				"target": { // can be an object with host and port, or a full url string e.g. "http://myproxy:80"
					"host": "hostname",
					"port": 80
				},
				"pathPatterns": [] // e.g. ["^/api/"]
			},
			"delay": { // (OPTIONAL) Adding delay to responses for some path patterns
				"pathPatterns": [], // e.g. ["^/api/"],
				"time": 2000 // the delay amount
			},
			"fixtures": [ // (OPTIONAL) Fixture definitions
				{
					"active": true, // On/Off switch for this fixture
					"request": {
						"methods": ["GET", "POST"],
						"pathPattern": "^/api/rest/foo",
						// (OPTIONAL) additional condition that checks that the provided object is a subset of
						// the request's payload. This check is relevant only for POST, PUT and OPTIONS methods
						"payload": {
							"name": "bar"
						}
					},
					"response": {
						"status": 200,
						"body": {
							"hello": "Nice Fixture"
						}
					}
				}
				// more fixtures...
			]
		}
		// more servers...
	]
}

Usage

$ swb

server-with-benefits's People

Contributors

galbi101 avatar

Stargazers

NOOB2868 avatar

Watchers

я котик пур-пур avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.