Skip to content

Commit

Permalink
fix: no more endpointOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Nov 16, 2019
1 parent 80b0093 commit f9a5e98
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/route-send-endpoint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { compile, matcher } from "multi-path-matcher";
import { SendEndpoint } from "@kronos-integration/endpoint";

/**
* Endpoint to link against a koa route
* Endpoint to link against a http route
*/
export class RouteSendEndpoint extends SendEndpoint {
/**
Expand Down
11 changes: 6 additions & 5 deletions src/service-koa.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export class ServiceKOA extends Service {
*/
}

/**
*
* @param {string} name
* @param {object|string} definition
* @return {Class} RouteSendEndpoint if path is present of name starts with '/'
*/
endpointFactoryFromConfig(name, definition) {
if (definition.path || name[0] === '/') {
return RouteSendEndpoint;
Expand All @@ -137,10 +143,6 @@ export class ServiceKOA extends Service {
return super.endpointFactoryFromConfig(name, definition);
}

endpointOptions(name, definition) {
return { ...super.endpointOptions(name, definition), ...definition };
}

get isSecure() {
return this.key !== undefined;
}
Expand All @@ -156,7 +158,6 @@ export class ServiceKOA extends Service {
return undefined;
}


get scheme() {
return this.isSecure ? "https" : "http";
}
Expand Down
22 changes: 16 additions & 6 deletions tests/route-endpoint-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test("endpoint route basics", async t => {
const ks = new ServiceKOA(
{
listen: {
socket: 1239
socket: 1240
}
},
sp
Expand All @@ -31,30 +31,33 @@ test("endpoint route basics", async t => {

await ks.start();

let response = await got("http://localhost:1239/r1");
let response = await got("http://localhost:1240/r1");
t.is(response.body, "OK S1");
t.is(response.statusCode, 200);

response = await got("http://localhost:1239/r2");
response = await got("http://localhost:1240/r2");
t.is(response.body, "OK S2");
t.is(response.statusCode, 200);

//response = await got("http://localhost:1239/r0");
//response = await got("http://localhost:1240/r0");

await ks.stop();
});

test("endpoint factory", async t => {
const sp = new StandaloneServiceProvider();

const s1 = new SendEndpoint("s1");
s1.receive = async () => "OK S1";

const http = await sp.declareService({
name: 'http',
type: ServiceKOA,
listen: {
socket: 1239
socket: 1241
},
endpoints: {
'/r1': {},
'/r1': { connected: s1 },
'/r2': { method: 'post' },
'/r3': { path: '/somwhere' }
}
Expand All @@ -69,4 +72,11 @@ test("endpoint factory", async t => {
t.is(http.endpoints['/r2'].method, 'POST');
t.is(http.endpoints['/r3'].path, '/somwhere');

http.koa.use(endpointRouter(http));

await http.start();

let response = await got("http://localhost:1241/r1");
t.is(response.body, "OK S1");
t.is(response.statusCode, 200);
});

0 comments on commit f9a5e98

Please sign in to comment.