diff --git a/src/route-send-endpoint.mjs b/src/route-send-endpoint.mjs index 27c3f7ef..4f466d4d 100644 --- a/src/route-send-endpoint.mjs +++ b/src/route-send-endpoint.mjs @@ -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 { /** diff --git a/src/service-koa.mjs b/src/service-koa.mjs index c72a84c1..8069211b 100644 --- a/src/service-koa.mjs +++ b/src/service-koa.mjs @@ -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; @@ -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; } @@ -156,7 +158,6 @@ export class ServiceKOA extends Service { return undefined; } - get scheme() { return this.isSecure ? "https" : "http"; } diff --git a/tests/route-endpoint-test.mjs b/tests/route-endpoint-test.mjs index cd29e8ca..ba7ae23b 100644 --- a/tests/route-endpoint-test.mjs +++ b/tests/route-endpoint-test.mjs @@ -11,7 +11,7 @@ test("endpoint route basics", async t => { const ks = new ServiceKOA( { listen: { - socket: 1239 + socket: 1240 } }, sp @@ -31,15 +31,15 @@ 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(); }); @@ -47,14 +47,17 @@ test("endpoint route basics", async t => { 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' } } @@ -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); });