@hubspot/local-dev-lib 2.2.0 → 2.3.0-beta.0
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/lib/portManager.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RequestPortsData } from '../types/PortManager';
|
|
2
2
|
export declare const BASE_URL: string;
|
|
3
|
+
export declare function isPortManagerPortAvailable(): Promise<boolean>;
|
|
3
4
|
export declare function isPortManagerServerRunning(): Promise<boolean>;
|
|
4
5
|
export declare function startPortManagerServer(): Promise<void>;
|
|
5
6
|
export declare function stopPortManagerServer(): Promise<void>;
|
package/lib/portManager.js
CHANGED
|
@@ -3,15 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.isPortManagerServerRunning = exports.BASE_URL = void 0;
|
|
6
|
+
exports.portManagerHasActiveServers = exports.deleteServerInstance = exports.requestPorts = exports.stopPortManagerServer = exports.startPortManagerServer = exports.isPortManagerServerRunning = exports.isPortManagerPortAvailable = exports.BASE_URL = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const PortManagerServer_1 = require("../utils/PortManagerServer");
|
|
9
|
-
const detectPort_1 = require("../utils/detectPort");
|
|
10
9
|
const ports_1 = require("../constants/ports");
|
|
10
|
+
const detectPort_1 = require("../utils/detectPort");
|
|
11
|
+
const logger_1 = require("./logger");
|
|
11
12
|
exports.BASE_URL = `http://localhost:${ports_1.PORT_MANAGER_SERVER_PORT}`;
|
|
13
|
+
async function isPortManagerPortAvailable() {
|
|
14
|
+
return ((await (0, detectPort_1.detectPort)(ports_1.PORT_MANAGER_SERVER_PORT)) === ports_1.PORT_MANAGER_SERVER_PORT);
|
|
15
|
+
}
|
|
16
|
+
exports.isPortManagerPortAvailable = isPortManagerPortAvailable;
|
|
12
17
|
async function isPortManagerServerRunning() {
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
try {
|
|
19
|
+
const { data } = await axios_1.default.get(`${exports.BASE_URL}${PortManagerServer_1.HEALTH_CHECK_PATH}`);
|
|
20
|
+
return data.status === PortManagerServer_1.SERVICE_HEALTHY;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
logger_1.logger.debug(e);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
15
26
|
}
|
|
16
27
|
exports.isPortManagerServerRunning = isPortManagerServerRunning;
|
|
17
28
|
async function startPortManagerServer() {
|
package/package.json
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { Express, Request, Response } from 'express';
|
|
3
3
|
import { Server } from 'http';
|
|
4
4
|
import { RequestPortsData, ServerPortMap } from '../types/PortManager';
|
|
5
|
+
export declare const HEALTH_CHECK_PATH = "/port-manager-health-check";
|
|
6
|
+
export declare const SERVICE_HEALTHY = "OK";
|
|
5
7
|
declare class _PortManagerServer {
|
|
6
8
|
app?: Express;
|
|
7
9
|
server?: Server;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.PortManagerServer = void 0;
|
|
6
|
+
exports.PortManagerServer = exports.SERVICE_HEALTHY = exports.HEALTH_CHECK_PATH = void 0;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
8
|
const cors_1 = __importDefault(require("cors"));
|
|
9
9
|
const detectPort_1 = require("./detectPort");
|
|
@@ -12,6 +12,8 @@ const errors_1 = require("../errors");
|
|
|
12
12
|
const logger_1 = require("../lib/logger");
|
|
13
13
|
const lang_1 = require("./lang");
|
|
14
14
|
const i18nKey = 'utils.PortManagerServer';
|
|
15
|
+
exports.HEALTH_CHECK_PATH = '/port-manager-health-check';
|
|
16
|
+
exports.SERVICE_HEALTHY = 'OK';
|
|
15
17
|
class _PortManagerServer {
|
|
16
18
|
app;
|
|
17
19
|
server;
|
|
@@ -29,6 +31,7 @@ class _PortManagerServer {
|
|
|
29
31
|
this.setupRoutes();
|
|
30
32
|
try {
|
|
31
33
|
this.server = await this.listen();
|
|
34
|
+
logger_1.logger.debug(this.server);
|
|
32
35
|
}
|
|
33
36
|
catch (e) {
|
|
34
37
|
if ((0, errors_1.isSystemError)(e) && e.code === 'EADDRINUSE') {
|
|
@@ -65,6 +68,9 @@ class _PortManagerServer {
|
|
|
65
68
|
this.app.post('/servers', this.assignPortsToServers);
|
|
66
69
|
this.app.delete('/servers/:instanceId', this.deleteServerInstance);
|
|
67
70
|
this.app.post('/close', this.closeServer);
|
|
71
|
+
this.app.use(exports.HEALTH_CHECK_PATH, (req, res) => {
|
|
72
|
+
res.status(200).send({ status: exports.SERVICE_HEALTHY });
|
|
73
|
+
});
|
|
68
74
|
}
|
|
69
75
|
setPort(instanceId, port) {
|
|
70
76
|
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.setPort`, { instanceId, port }));
|