@empyria/restate 0.4.20 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/Admin.js +8 -12
- package/package.json +1 -1
- package/test/Admin.test.js +5 -3
package/README.md
CHANGED
|
@@ -125,9 +125,9 @@ Cron expressions are `croner` patterns (five fields, or six with seconds for tes
|
|
|
125
125
|
### Serving and registering an endpoint
|
|
126
126
|
|
|
127
127
|
`setupRestate({ restateAdminURL, serviceURL: 'https://agent-service.internal:9080', services })` takes one complete URL, the
|
|
128
|
-
address Restate reaches the endpoint at. It is registered as given and the endpoint listens on its port
|
|
129
|
-
|
|
130
|
-
unless `healthPort` is set.
|
|
128
|
+
address Restate reaches the endpoint at. It is registered as given and the endpoint listens on its port (80 or 443 when
|
|
129
|
+
the URL has none or states the scheme's default), so the scheme is required (there is no separate host or port option);
|
|
130
|
+
the health endpoint listens on the next port unless `healthPort` is set.
|
|
131
131
|
|
|
132
132
|
It serves, registers the deployment, and deletes it again on SIGINT/SIGTERM. Invocations in flight are
|
|
133
133
|
pinned to their deployment, so deleting it strands them: a restarted process cannot finish them and they can only be
|
package/lib/Admin.js
CHANGED
|
@@ -620,9 +620,9 @@ export function defaultHealthCheck(req, res, { isHealthy, deploymentId, services
|
|
|
620
620
|
* that was removed or renamed cannot resume.
|
|
621
621
|
* @param {Object} params
|
|
622
622
|
* @param {string} params.restateAdminURL
|
|
623
|
-
* @param {string} params.serviceURL Complete URL Restate uses to reach this endpoint
|
|
624
|
-
*
|
|
625
|
-
* the
|
|
623
|
+
* @param {string} params.serviceURL Complete URL Restate uses to reach this endpoint (e.g.
|
|
624
|
+
* `https://agent-service.internal:9080`). It is registered as given, and the endpoint listens on its port: 80 or 443
|
|
625
|
+
* when the URL has none or states the scheme's default (listening there needs the privilege to bind it).
|
|
626
626
|
* @param {number} [params.healthPort] - Defaults to `port + 1`.
|
|
627
627
|
* @param {Parameters<typeof restate.createEndpointHandler>[0]['services']} [params.services]
|
|
628
628
|
* @param {() => void} [params.shutdownCallbackFn]
|
|
@@ -792,10 +792,9 @@ export async function setupRestate({
|
|
|
792
792
|
|
|
793
793
|
/**
|
|
794
794
|
* Validates the URL `setupRestate` registers with Restate and returns it with the port the endpoint listens on.
|
|
795
|
-
* @param {string} serviceURL Complete http(s) URL
|
|
795
|
+
* @param {string} serviceURL Complete http(s) URL; a port left out (or equal to the scheme's default) means 80/443
|
|
796
796
|
* @returns {{serviceURL: string, port: number}} `serviceURL` unchanged
|
|
797
|
-
* @throws {Error} If it is missing
|
|
798
|
-
* be a guess)
|
|
797
|
+
* @throws {Error} If it is missing or not an absolute http(s) URL
|
|
799
798
|
*/
|
|
800
799
|
export function parseServiceURL(serviceURL) {
|
|
801
800
|
if (!serviceURL) {
|
|
@@ -814,12 +813,9 @@ export function parseServiceURL(serviceURL) {
|
|
|
814
813
|
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
815
814
|
throw new Error(`serviceURL must use http or https, got '${serviceURL}'`)
|
|
816
815
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
)
|
|
821
|
-
}
|
|
822
|
-
return { serviceURL, port: Number(url.port) }
|
|
816
|
+
// `URL.port` is '' for the scheme's default port, written or not; that is the port Restate dials, so listen on it.
|
|
817
|
+
const port = url.port ? Number(url.port) : url.protocol === 'https:' ? 443 : 80
|
|
818
|
+
return { serviceURL, port }
|
|
823
819
|
}
|
|
824
820
|
|
|
825
821
|
/**
|
package/package.json
CHANGED
package/test/Admin.test.js
CHANGED
|
@@ -566,9 +566,11 @@ describe('parseServiceURL', () => {
|
|
|
566
566
|
expect(() => parseServiceURL('ftp://svc:21')).toThrow(/http or https/)
|
|
567
567
|
})
|
|
568
568
|
|
|
569
|
-
test(
|
|
570
|
-
expect(
|
|
571
|
-
expect(
|
|
569
|
+
test("uses the scheme's default port when the URL has none or states it", () => {
|
|
570
|
+
expect(parseServiceURL('https://svc.example.com').port).toBe(443)
|
|
571
|
+
expect(parseServiceURL('https://svc.example.com:443').port).toBe(443)
|
|
572
|
+
expect(parseServiceURL('http://svc').port).toBe(80)
|
|
573
|
+
expect(parseServiceURL('http://svc:80').port).toBe(80)
|
|
572
574
|
})
|
|
573
575
|
})
|
|
574
576
|
|