# mscp

> TBD!

Latest version **1.3.7** (published 2020-12-17) · 0 weekly downloads

## Install

```sh
npm install mscp
pnpm add mscp
yarn add mscp
bun add mscp
```

Provides the command `mscp`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.7 |
| Published | 2020-12-17 |
| First published | 2017-02-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.0.0 |
| Dependencies | 13 |
| Unpacked size | 155.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | palantus |

## Links

- npm: https://www.npmjs.com/package/mscp
- Repository: https://github.com/palantus/mscp
- Homepage: https://github.com/palantus/mscp#readme
- Issues: https://github.com/palantus/mscp/issues
- npm.io page: https://npm.io/package/mscp

## Dependencies (13)

- [ws](https://npm.io/package/ws.md) *
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [spdy](https://npm.io/package/spdy.md) *
- [express](https://npm.io/package/express.md) *
- [request](https://npm.io/package/request.md) *
- [commander](https://npm.io/package/commander.md) *
- [node-uuid](https://npm.io/package/node-uuid.md) *
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.2
- [js2xmlparser](https://npm.io/package/js2xmlparser.md) ^3.0.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) *
- [memory-streams](https://npm.io/package/memory-streams.md) ^0.1.3
- [mscp-browserlibs](https://npm.io/package/mscp-browserlibs.md) *
- [express-fileupload](https://npm.io/package/express-fileupload.md) *

## Recent versions

- 1.3.7 (latest) — 2020-12-17
- 1.3.6 — 2020-12-07
- 1.3.5 — 2020-07-29
- 1.3.4 — 2019-11-20
- 1.3.2 — 2019-11-19
- 1.3.1 — 2019-11-19
- 1.3.0 — 2019-11-19
- 1.2.99 — 2019-11-19
- 1.2.98 — 2019-11-19
- 1.2.97 — 2019-10-31
- 1.2.96 — 2019-10-17
- 1.2.95 — 2019-09-19
- 1.2.94 — 2019-09-04
- 1.2.93 — 2019-03-21
- 1.2.92 — 2019-03-08
- … 107 more at https://npm.io/package/mscp/versions

## README

# MSCP: MicroService Communication Platform

TBD!

## Sample server/client
```javascript
const MSCP = require("mscp");
const Handler = require("./handler.js");
const path = require("path");

(async () => {
  let mscp = new MSCP(Handler)
  mscp.server.static(path.join(__dirname, 'www'));
  mscp.start();
})()
```

The handler constructor argument for MSCP can be either a single class (no namespaces) or an object. If it is an object, then it maps namespaces to handler classes. The root handler is "".

In your handler, you can access the context of the current reqest using the properties:
- this.mscp: reference to mscp class
- this.definition: reference to the definition.json file parsed as an object
- this.global: An empty object that is the same between requests
- this.request = An object containing path (url path of request), data (all url/post parameters) and req (express req object - has mscp.ip and mscp.accessKey)

## Sample browser client:

```HTML
<script src="/mscp/js/browser.js"></script>
<script src="/mscp/js/jquery.min.js"></script>
<script>
$(function() {
  mscp.ready.then(myFunction)
});

async function myFunction(){
  let value = await mscp.getValue("123")
  console.log(value)
}
</script>
```

## Requirements

You need note 7+ and (if version < 8) the node flag ```--harmony-async-await```.
For the browser client, you need Chrome 56 or Firefox 52 (for async/await).

## Setup parameters

- trustProxy: Instructs Express to trust the proxy that sent the request. Only use, when you are behind a proxy that you trust.
- useForwardedHeader: If set to true, then the security module will check the headers for 'x-forwarded-for' header to get the IP of the client, instead of the proxy server. Only use this, if you are behind a proxy that sets this variable.
- useRealIPHeader: If set to true, then the security module will check the headers for 'x-real-ip' header to get the IP of the client, instead of the proxy server. Only use this, if you are behind a proxy that sets this variable.

## Sample simple UI


```
TBD
```

## Sample UI Setup, with a single function as entry:

```JSON
{
  "apps": {
    "": {"title": "Starter", "items": ["services", "kill", "log"], "defaultIndex": 0, "showMenu": false}
  },
  "items": {
    "services": {
      "title":" List services",
      "autorun": true,
      "actions":{
        "<row>": [
          {"call": "log", "title": "View log", "args": {"name": "active.name"}},
          {"call": "setup", "title": "Show setup", "args": {"name": "active.name"}},
          {"call": "gitpull", "title": "Execute: git pull", "args": {"name": "active.name"}, "ui": "notify-result", "notifytimeout": 7000},
          {"call": "npminstall", "title": "Execute: npm install", "args": {"name": "active.name"}, "ui": "notify-result", "notifytimeout": 7000},
          {"call": "kill", "title": "Force stop", "args": {"name": "active.name"}, "ui": "notify-result"},
          {"call": "enableService", "title": "Enable", "args": {"name": "active.name"}, "ui": "notify-result", "rerunParentAfter": true},
          {"call": "disableService", "title": "Disable", "args": {"name": "active.name"}, "ui": "notify-result", "rerunParentAfter": true},
          {"type": "link", "url": "<curhostnoport>:<active.http_port>/mscp", "title": "Open: MSCP Setup"},
          {"type": "link", "url": "<curhostnoport>:<active.http_port>/api/browse", "title": "Open: API Browser"},
          {"type": "link", "url": "<curhostnoport>:<active.http_port>", "title": "Open: Root"}
        ],
        "": [
          {"type": "link", "item": "services", "title": "Refresh"}
        ]
      }
    },
    "log": {"title":"Get log"},
    "kill": {"title":"Restart service"}
  }
}
```

## Reserved URL parameters:
- accessKey: used when securing (som parts of) the server with access keys
- responseType: can be used to set response type to XML instead of JSON


## CORS

You can enable CORS by setting ''allowedOrigins'' in ''setup.json'' to the domains that should be allowed. It supports regexps.

If you want to allow all cors (send *), then just set it to ''*'', would would make it use the cors npm module with default options.

If you want to allow all, including credentials, then set it to ''**''.

## Access keys

Access keys expire every 18 days by default, but can be extended by setting ''accessKeyExpirationDays'' in setup.json.

## Depend on download function
You can access the file if you call a download function dependency like this:

```javascript
let file = await this.mscp.files.download.call(this, "123")
file.toBuffer().toString()
```

---
_Source: https://npm.io/package/mscp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
