Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agreed/server

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agreed/server

agreed server

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
97
decreased by-6.73%
Maintainers
2
Weekly downloads
 
Created
Source

Agreed Server

Build Status

Agreed mock server

agreed-server is a mock server based on agreed. This module provides CLI executable command and 2 programmable interface. If you want to use agreed as mock, you would be better to install agreed-server.

Install

$ npm install agreed-server --save-dev

Basic Usage

Usage as CLI

$ agreed-server --path ./test/agreed.json --port 10101
  • if you want to boot agreed server as disable hot replacement.
$ agreed-server --path ./test/agreed.json --port 10101 --hot false

Usage as programming

const agreedServer = require('agreed-server');

const server = agreedServer({
  path: 'agreed/agreed.json',
  port: 3001,
  static: './static', // serve files from ./static
  staticPrefixPath: '/public',
}).createServer();

Advanced Usage

Usage as Express pure server

const agreedServer = require('agreed-server');

const { app, createServer } = agreedServer({
  path: 'agreed/agreed.json',
  port: 3001,
  static: './static', // serve files from ./static
  staticPrefixPath: '/public',
  middlewares: [
    logger,
    perfTool,
    secureHeaders,
  ],
  defaultRequestHeaders: {
    'x-forwarded-for': 'nginx'
  },
  defaultResponseHeaders: {
    'access-control-allow-origin': '*'
  },
});

app.use(someGoodMiddleware);
app.use((err, req, res, next) => {
  res.statusCode = 500;
  res.send(`Error is occurred : ${err}, you should see log`);
});
const server = createServer(app);

notifier

Usage as notification event

agreed file

module.exports = [
  {
    request: {
      path: '/messages',
      method: 'POST',
      body: {
        message: '{:message}'
      },
      values: {
        message: 'test',
      },
    },
    response: {
      body: {
        result : '{:message}'
      },
      values: {
        message: 'test',
      },
      // add notify property for notification
      notify: {
        body: {
          message: 'message! {:message}'
        }
      }
    },
  },
]
const agreedServer = require('agreed-server');

const { app, createServer, notifier } = agreedServer({
  path: 'agreed/agreed.json',
  port: 3001,
  static: './static', // serve files from ./static
  staticPrefixPath: '/public',
  middlewares: [
    logger,
    perfTool,
    secureHeaders,
  ],
  defaultRequestHeaders: {
    'x-forwarded-for': 'nginx'
  },
  defaultResponseHeaders: {
    'access-control-allow-origin': '*'
  },
});

notifier.on('message', (data) => {
  console.log(data) // { message: 'message! hoge' }
});

app.use(someGoodMiddleware);
app.use((err, req, res, next) => {
  res.statusCode = 500;
  res.send(`Error is occurred : ${err}, you should see log`);
});
const server = createServer(app);

Keywords

FAQs

Package last updated on 19 Dec 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc