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

smoke

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smoke - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

3

CHANGELOG.md

@@ -0,1 +1,4 @@

# 3.1.0
- Add CORS option (PR https://github.com/sinedied/smoke/pull/11)
# 3.0.0

@@ -2,0 +5,0 @@ - Bump dependencies and fix vulnerabilities

@@ -6,2 +6,3 @@ const path = require('path');

const proxy = require('express-http-proxy');
const corsMiddleWare = require('cors');

@@ -23,2 +24,27 @@ const {getMocks} = require('./mock');

let allowedOrigins = options.cors ? options.cors.split(',') : [];
allowedOrigins = allowedOrigins.map((val) => val.trim());
if (allowedOrigins.length === 0 || allowedOrigins.includes('all')) {
app.use(corsMiddleWare());
} else {
app.use(
corsMiddleWare({
origin: (origin, callback) => {
/**
* Allow requests with no 'origin'
* i.e. mobile apps, curl etc.
*/
if (!origin) return callback(null, true);
if (!allowedOrigins.includes(origin)) {
const msg = `The CORS policy for this mock does not allow access from the specified origin: ${origin}. For details on how to whitelist requests from this origin, refer to --help.`;
return callback(new Error(msg), false);
}
return callback(null, true);
}
})
);
}
let hooks = {before: [], after: []};

@@ -70,3 +96,4 @@

saveHeaders: options.saveHeaders || false,
saveQueryParams: options.saveQueryParams || false
saveQueryParams: options.saveQueryParams || false,
cors: options.cors || null
};

@@ -73,0 +100,0 @@ }

9

package.json
{
"name": "smoke",
"version": "3.0.0",
"version": "3.1.0",
"description": "Simple yet powerful file-based mock server with recording abilities",

@@ -42,4 +42,5 @@ "repository": {

"body-parser": "^1.19.0",
"cors": "2.8.5",
"express": "^4.17.1",
"express-http-proxy": "^1.6.0",
"express-http-proxy": "^1.6.2",
"fs-extra": "^9.0.1",

@@ -56,5 +57,5 @@ "globby": "^11.0.1",

"devDependencies": {
"jest": "^26.1.0",
"jest": "^26.4.2",
"supertest": "^4.0.2",
"xo": "^0.32.0"
"xo": "^0.32.1"
},

@@ -61,0 +62,0 @@ "xo": {

@@ -39,2 +39,3 @@ # :dash: smoke

- Mock only specific requests and proxy the rest to an existing server
- Supports CORS (cross-origin resource-sharing)

@@ -56,19 +57,20 @@ ## Installation

Base options:
-p, --port <num> Server port [default: 3000]
-h, --host <host> Server host [default: "localhost"]
-s, --set <name> Mocks set to use [default: none]
-n, --not-found <glob> Mocks for 404 errors [default: "404.*"]
-i, --ignore <glob> Files to ignore [default: none]
-k, --hooks <file> Middleware hooks [default: none]
-x, --proxy <host> Fallback proxy if no mock found
-l, --logs Enable server logs
-v, --version Show version
--help Show help
-p, --port <num> Server port [default: 3000]
-h, --host <host> Server host [default: "localhost"]
-s, --set <name> Mocks set to use [default: none]
-n, --not-found <glob> Mocks for 404 errors [default: "404.*"]
-i, --ignore <glob> Files to ignore [default: none]
-k, --hooks <file> Middleware hooks [default: none]
-x, --proxy <host> Fallback proxy if no mock found
-o, --allow-cors [all|<hosts>] Enable CORS requests [default: none]
-l, --logs Enable server logs
-v, --version Show version
--help Show help
Mock recording:
-r, --record <host> Proxy & record requests if no mock found
-c, --collection <file> Save to single file mock collection
-d, --depth <N> Folder depth for mocks [default: 1]
-a, --save-headers Save response headers
-q, --save-query Save query parameters
-r, --record <host> Proxy & record requests if no mock found
-c, --collection <file> Save to single file mock collection
-d, --depth <N> Folder depth for mocks [default: 1]
-a, --save-headers Save response headers
-q, --save-query Save query parameters
```

@@ -306,2 +308,12 @@

## Enabling CORS
Smoke offers support to requests originating from a different origin. However, by default, this would be disabled.
To enable CORS, pass the hosts that you want to allow to `-o` or `--allow-cors` arguments.
**Accepted Values**
- `all` - Allow requests from `*`
- `<hosts>` - You could also pass a comma-separated list of hosts that you want to allow requests from something like `'http://localhost:3000,http://example.com'`
### Single file mock collection

@@ -308,0 +320,0 @@

@@ -8,19 +8,20 @@ const minimist = require('minimist');

Base options:
-p, --port <num> Server port [default: 3000]
-h, --host <host> Server host [default: "localhost"]
-s, --set <name> Mocks set to use [default: none]
-n, --not-found <glob> Mocks for 404 errors [default: "404.*"]
-i, --ignore <glob> Files to ignore [default: none]
-k, --hooks <file> Middleware hooks [default: none]
-x, --proxy <host> Fallback proxy if no mock found
-l, --logs Enable server logs
-v, --version Show version
--help Show help
-p, --port <num> Server port [default: 3000]
-h, --host <host> Server host [default: "localhost"]
-s, --set <name> Mocks set to use [default: none]
-n, --not-found <glob> Mocks for 404 errors [default: "404.*"]
-i, --ignore <glob> Files to ignore [default: none]
-k, --hooks <file> Middleware hooks [default: none]
-x, --proxy <host> Fallback proxy if no mock found
-o, --allow-cors [all|<hosts>] Enable CORS requests [default: none]
-l, --logs Enable server logs
-v, --version Show version
--help Show help
Mock recording:
-r, --record <host> Proxy & record requests if no mock found
-c, --collection <file> Save to single file mock collection
-d, --depth <N> Folder depth for mocks [default: 1]
-a, --save-headers Save response headers
-q, --save-query Save query parameters
-r, --record <host> Proxy & record requests if no mock found
-c, --collection <file> Save to single file mock collection
-d, --depth <N> Folder depth for mocks [default: 1]
-a, --save-headers Save response headers
-q, --save-query Save query parameters
`;

@@ -31,3 +32,3 @@

number: ['port', 'depth'],
string: ['host', 'set', 'not-found', 'record', 'ignore', 'hooks', 'proxy', 'collection'],
string: ['host', 'set', 'not-found', 'record', 'ignore', 'hooks', 'proxy', 'collection', 'allow-cors'],
boolean: ['help', 'version', 'logs', 'save-headers', 'save-query'],

@@ -47,3 +48,4 @@ alias: {

k: 'hooks',
x: 'proxy'
x: 'proxy',
o: 'allow-cors'
}

@@ -75,3 +77,4 @@ });

saveHeaders: options['save-headers'],
saveQueryParams: options['save-query']
saveQueryParams: options['save-query'],
cors: options['allow-cors']
});

@@ -78,0 +81,0 @@

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