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

@b4dnewz/express-test-server

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@b4dnewz/express-test-server - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

1

lib/index.js

@@ -10,3 +10,2 @@ "use strict";

if (opts === void 0) { opts = {
bodyParser: true,
certificate: false,

@@ -13,0 +12,0 @@ }; }

9

lib/server.d.ts

@@ -11,3 +11,8 @@ /// <reference types="node" />

}
export interface ServerOptions {
interface ListenOptions {
hostname?: string;
port?: number;
sslPort?: number;
}
export interface ServerOptions extends ListenOptions {
bodyParser?: boolean | bodyParser.Options;

@@ -25,3 +30,3 @@ listen?: boolean;

sslUrl?: string;
listen(): Promise<void[]>;
listen(opts: ListenOptions): Promise<void[]>;
close(): Promise<void[]>;

@@ -28,0 +33,0 @@ }

@@ -47,3 +47,3 @@ "use strict";

function createServer(keys, options) {
options = __assign({ listen: true }, options);
options = __assign({ bodyParser: true, listen: true }, options);
var server = express_1.default();

@@ -78,13 +78,15 @@ server.http = http.createServer(server);

});
server.listen = function () {
server.listen = function (_a) {
var _b = _a === void 0 ? {} : _a, hostname = _b.hostname, port = _b.port, sslPort = _b.sslPort;
hostname = hostname || "localhost";
var promises = [
util_1.promisify(server.http.listen.bind(server.http))().then(function () {
util_1.promisify(server.http.listen.bind(server.http))(port, hostname).then(function () {
server.port = server.http.address().port;
server.url = "http://localhost:" + server.port;
server.url = "http://" + hostname + ":" + server.port;
}),
];
if (server.https) {
promises.push(util_1.promisify(server.https.listen.bind(server.https))().then(function () {
promises.push(util_1.promisify(server.https.listen.bind(server.https))(sslPort, hostname).then(function () {
server.sslPort = server.https.address().port;
server.sslUrl = "https://localhost:" + server.sslPort;
server.sslUrl = "https://" + hostname + ":" + server.sslPort;
}));

@@ -112,4 +114,4 @@ }

}
return server.listen().then(function () { return server; });
return server.listen(options).then(function () { return server; });
}
exports.createServer = createServer;
{
"name": "@b4dnewz/express-test-server",
"version": "0.1.0",
"version": "0.1.1",
"description": "A minimal but customizable Express server for testing",

@@ -39,2 +39,3 @@ "homepage": "https://github.com/b4dnewz/express-test-server",

"coveralls": "^3.0.4",
"get-port": "^5.0.0",
"got": "^9.6.0",

@@ -41,0 +42,0 @@ "jest": "^24.8.0",

@@ -63,4 +63,51 @@ # express-test-server

## Options
__port__ (default 0)
Specify a custom port for the HTTP server instance, otherwise it will automatically choose a random free TCP port
```js
await createServer({
port: 8888
})
```
__sslPort__ (default _443_)
Specify a custom port for the HTTPS server instance, otherwise it will try to default ssl port
```js
await createServer({
sslPort: 4443
})
```
__hostname__ (default _localhost_)
Specify a custom hostname for both HTTP and HTTPS servers, remember that you need a resolvable DNS host name for this to work.
```js
await createServer({
hostname: "0.0.0.0"
})
await createServer({
hostname: "test.example.com"
})
```
__listen__ (default _true_)
If false will prevent the test server to automatically start to listen for requests when instanciated.
```js
const server = await createServer({
listen: false
})
// listen later on a desired port
await server.listen({
port: 8888
})
```
## License
MIT
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