From ed6e1fe38f220f5438a2418fae6481dd440c9e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20W=C3=BCthrich?= Date: Tue, 8 Jan 2019 15:34:16 +0100 Subject: [PATCH] Only replace ~ at the beginning of service name (eg. "~node") --- src/index.js | 3 ++- test/integration/index.spec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 01fc3e60..3a806678 100644 --- a/src/index.js +++ b/src/index.js @@ -305,7 +305,8 @@ module.exports = { if (urlPath.startsWith("/")) urlPath = urlPath.slice(1); - urlPath = urlPath.replace(/~/, "$"); + // Resolve $node service + urlPath = urlPath.replace(/^~/, "$"); let action = urlPath; // Resolve aliases diff --git a/test/integration/index.spec.js b/test/integration/index.spec.js index 5d1ed92b..06c059ae 100644 --- a/test/integration/index.spec.js +++ b/test/integration/index.spec.js @@ -856,6 +856,25 @@ describe("Test aliases", () => { }); }); + it("GET /api/greeter/~Tilde~", () => { + return request(server) + .get("/api/greeter/~Tilde~") + .then(res => { + expect(res.statusCode).toBe(200); + expect(res.headers["content-type"]).toBe("application/json; charset=utf-8"); + expect(res.body).toBe("Hello ~Tilde~"); + }); + }); + + it("GET /api/~node/health", () => { + return request(server) + .get("/api/~node/health") + .then(res => { + expect(res.statusCode).toBe(200); + expect(res.headers["content-type"]).toBe("application/json; charset=utf-8"); + }); + }); + it("POST /api/greeter/Norbert", () => { return request(server) .post("/api/greeter/Norbert")