Skip to content

Commit

Permalink
fix: prevent url / socket / address deep recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Nov 8, 2019
1 parent c82882b commit 1833699
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@ koa backed http server
### Table of Contents

- [ServiceKOA](#servicekoa)
- [Parameters](#parameters)
- [Properties](#properties)
- [name](#name)
- [RouteSendEndpoint](#routesendendpoint)
- [Parameters](#parameters-1)

## ServiceKOA

**Extends Service**

HTTP server with koa

**Parameters**
### Parameters

- `config`
- `owner`

### Properties

- `server` **http.Server** only present if state is running
- `koa` **koa**

### name

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'koa'
Expand All @@ -48,13 +56,13 @@ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/G

Endpoint to link against a koa route

**Parameters**
### Parameters

- `name`
- `owner`
- `name` {string} endpoint name
- `owner` {Step} the owner of the endpoint
- `path`
- `method`
- `serviceName`
- `method` {string} http method defaults to get
- `serviceName` {string} if present registers the route as a service

# install

Expand Down
4 changes: 2 additions & 2 deletions src/service-koa.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class ServiceKOA extends Service {
get socket() {
const socket = this.listen.socket;
if(socket) { return socket; }
const url = this.url;
const url = this.listen.url;
if(url) {
const u = new URL(url);
return Number(u.port);
Expand All @@ -156,7 +156,7 @@ export class ServiceKOA extends Service {
get address() {
const address = this.listen.address;
if(address) { return address; }
const url = this.url;
const url = this.listen.url;
if(url) {
const u = new URL(url);
return u.hostname;
Expand Down
4 changes: 1 addition & 3 deletions tests/failure-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ServiceProvider extends ServiceProviderMixin(Service) {}
const sp = new ServiceProvider();

test("service-koa failures with already in use port", async t => {
const port = 1235;
const port = 1238;

const ks1 = new ServiceKOA(
{
Expand All @@ -18,7 +18,6 @@ test("service-koa failures with already in use port", async t => {
},
sp
);

const ks2 = new ServiceKOA(
{
name: "my-name2",
Expand All @@ -33,7 +32,6 @@ test("service-koa failures with already in use port", async t => {
t.is(ks1.state, "running");

await t.throwsAsync(() => ks2.start(), Error, 'listen EADDRINUSE: address already in use :::1235');

t.is(ks2.state, "failed");

await ks1.stop();
Expand Down

0 comments on commit 1833699

Please sign in to comment.