hotstaq 0.5.24

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.
Files changed (299) hide show
  1. package/.eslintignore +17 -0
  2. package/.eslintrc.js +11 -0
  3. package/.vscode/launch.json +199 -0
  4. package/.vscode/settings.json +2 -0
  5. package/.vscode/tasks.json +78 -0
  6. package/CONTRIBUTING.md +157 -0
  7. package/README.md +126 -0
  8. package/bin/hotstaq +3 -0
  9. package/bin/hotstaq.cmd +1 -0
  10. package/build/src/Hot.d.ts +167 -0
  11. package/build/src/Hot.d.ts.map +1 -0
  12. package/build/src/Hot.js +365 -0
  13. package/build/src/Hot.js.map +1 -0
  14. package/build/src/HotAPI.d.ts +130 -0
  15. package/build/src/HotAPI.d.ts.map +1 -0
  16. package/build/src/HotAPI.js +353 -0
  17. package/build/src/HotAPI.js.map +1 -0
  18. package/build/src/HotAgentAPI.d.ts +22 -0
  19. package/build/src/HotAgentAPI.d.ts.map +1 -0
  20. package/build/src/HotAgentAPI.js +85 -0
  21. package/build/src/HotAgentAPI.js.map +1 -0
  22. package/build/src/HotAgentRoute.d.ts +17 -0
  23. package/build/src/HotAgentRoute.d.ts.map +1 -0
  24. package/build/src/HotAgentRoute.js +109 -0
  25. package/build/src/HotAgentRoute.js.map +1 -0
  26. package/build/src/HotBuilder.d.ts +52 -0
  27. package/build/src/HotBuilder.d.ts.map +1 -0
  28. package/build/src/HotBuilder.js +239 -0
  29. package/build/src/HotBuilder.js.map +1 -0
  30. package/build/src/HotClient.d.ts +31 -0
  31. package/build/src/HotClient.d.ts.map +1 -0
  32. package/build/src/HotClient.js +19 -0
  33. package/build/src/HotClient.js.map +1 -0
  34. package/build/src/HotComponent.d.ts +118 -0
  35. package/build/src/HotComponent.d.ts.map +1 -0
  36. package/build/src/HotComponent.js +89 -0
  37. package/build/src/HotComponent.js.map +1 -0
  38. package/build/src/HotCreator.d.ts +92 -0
  39. package/build/src/HotCreator.d.ts.map +1 -0
  40. package/build/src/HotCreator.js +465 -0
  41. package/build/src/HotCreator.js.map +1 -0
  42. package/build/src/HotDB.d.ts +69 -0
  43. package/build/src/HotDB.d.ts.map +1 -0
  44. package/build/src/HotDB.js +29 -0
  45. package/build/src/HotDB.js.map +1 -0
  46. package/build/src/HotDBConnectionInterface.d.ts +40 -0
  47. package/build/src/HotDBConnectionInterface.d.ts.map +1 -0
  48. package/build/src/HotDBConnectionInterface.js +3 -0
  49. package/build/src/HotDBConnectionInterface.js.map +1 -0
  50. package/build/src/HotFile.d.ts +134 -0
  51. package/build/src/HotFile.d.ts.map +1 -0
  52. package/build/src/HotFile.js +454 -0
  53. package/build/src/HotFile.js.map +1 -0
  54. package/build/src/HotHTTPServer.d.ts +162 -0
  55. package/build/src/HotHTTPServer.d.ts.map +1 -0
  56. package/build/src/HotHTTPServer.js +863 -0
  57. package/build/src/HotHTTPServer.js.map +1 -0
  58. package/build/src/HotIO.d.ts +39 -0
  59. package/build/src/HotIO.d.ts.map +1 -0
  60. package/build/src/HotIO.js +195 -0
  61. package/build/src/HotIO.js.map +1 -0
  62. package/build/src/HotLog.d.ts +60 -0
  63. package/build/src/HotLog.d.ts.map +1 -0
  64. package/build/src/HotLog.js +126 -0
  65. package/build/src/HotLog.js.map +1 -0
  66. package/build/src/HotPage.d.ts +125 -0
  67. package/build/src/HotPage.d.ts.map +1 -0
  68. package/build/src/HotPage.js +178 -0
  69. package/build/src/HotPage.js.map +1 -0
  70. package/build/src/HotRoute.d.ts +82 -0
  71. package/build/src/HotRoute.d.ts.map +1 -0
  72. package/build/src/HotRoute.js +83 -0
  73. package/build/src/HotRoute.js.map +1 -0
  74. package/build/src/HotRouteMethod.d.ts +129 -0
  75. package/build/src/HotRouteMethod.d.ts.map +1 -0
  76. package/build/src/HotRouteMethod.js +84 -0
  77. package/build/src/HotRouteMethod.js.map +1 -0
  78. package/build/src/HotServer.d.ts +152 -0
  79. package/build/src/HotServer.d.ts.map +1 -0
  80. package/build/src/HotServer.js +109 -0
  81. package/build/src/HotServer.js.map +1 -0
  82. package/build/src/HotSetAsWeb.d.ts +2 -0
  83. package/build/src/HotSetAsWeb.d.ts.map +1 -0
  84. package/build/src/HotSetAsWeb.js +5 -0
  85. package/build/src/HotSetAsWeb.js.map +1 -0
  86. package/build/src/HotStaq.d.ts +601 -0
  87. package/build/src/HotStaq.d.ts.map +1 -0
  88. package/build/src/HotStaq.js +1258 -0
  89. package/build/src/HotStaq.js.map +1 -0
  90. package/build/src/HotStaqWeb.d.ts +18 -0
  91. package/build/src/HotStaqWeb.d.ts.map +1 -0
  92. package/build/src/HotStaqWeb.js +44 -0
  93. package/build/src/HotStaqWeb.js.map +1 -0
  94. package/build/src/HotTestDriver.d.ts +63 -0
  95. package/build/src/HotTestDriver.d.ts.map +1 -0
  96. package/build/src/HotTestDriver.js +187 -0
  97. package/build/src/HotTestDriver.js.map +1 -0
  98. package/build/src/HotTestElement.d.ts +71 -0
  99. package/build/src/HotTestElement.d.ts.map +1 -0
  100. package/build/src/HotTestElement.js +37 -0
  101. package/build/src/HotTestElement.js.map +1 -0
  102. package/build/src/HotTestMap.d.ts +83 -0
  103. package/build/src/HotTestMap.d.ts.map +1 -0
  104. package/build/src/HotTestMap.js +58 -0
  105. package/build/src/HotTestMap.js.map +1 -0
  106. package/build/src/HotTestSeleniumDriver.d.ts +82 -0
  107. package/build/src/HotTestSeleniumDriver.d.ts.map +1 -0
  108. package/build/src/HotTestSeleniumDriver.js +398 -0
  109. package/build/src/HotTestSeleniumDriver.js.map +1 -0
  110. package/build/src/HotTester.d.ts +188 -0
  111. package/build/src/HotTester.d.ts.map +1 -0
  112. package/build/src/HotTester.js +623 -0
  113. package/build/src/HotTester.js.map +1 -0
  114. package/build/src/HotTesterAPI.d.ts +15 -0
  115. package/build/src/HotTesterAPI.d.ts.map +1 -0
  116. package/build/src/HotTesterAPI.js +161 -0
  117. package/build/src/HotTesterAPI.js.map +1 -0
  118. package/build/src/HotTesterMocha.d.ts +50 -0
  119. package/build/src/HotTesterMocha.d.ts.map +1 -0
  120. package/build/src/HotTesterMocha.js +205 -0
  121. package/build/src/HotTesterMocha.js.map +1 -0
  122. package/build/src/HotTesterMochaSelenium.d.ts +70 -0
  123. package/build/src/HotTesterMochaSelenium.d.ts.map +1 -0
  124. package/build/src/HotTesterMochaSelenium.js +257 -0
  125. package/build/src/HotTesterMochaSelenium.js.map +1 -0
  126. package/build/src/HotTesterServer.d.ts +114 -0
  127. package/build/src/HotTesterServer.d.ts.map +1 -0
  128. package/build/src/HotTesterServer.js +575 -0
  129. package/build/src/HotTesterServer.js.map +1 -0
  130. package/build/src/api.d.ts +33 -0
  131. package/build/src/api.d.ts.map +1 -0
  132. package/build/src/api.js +78 -0
  133. package/build/src/api.js.map +1 -0
  134. package/build/src/cli.d.ts +2 -0
  135. package/build/src/cli.d.ts.map +1 -0
  136. package/build/src/cli.js +935 -0
  137. package/build/src/cli.js.map +1 -0
  138. package/build/src/schemas/HotDBInflux.d.ts +63 -0
  139. package/build/src/schemas/HotDBInflux.d.ts.map +1 -0
  140. package/build/src/schemas/HotDBInflux.js +239 -0
  141. package/build/src/schemas/HotDBInflux.js.map +1 -0
  142. package/build/src/schemas/HotDBMigration.d.ts +19 -0
  143. package/build/src/schemas/HotDBMigration.d.ts.map +1 -0
  144. package/build/src/schemas/HotDBMigration.js +15 -0
  145. package/build/src/schemas/HotDBMigration.js.map +1 -0
  146. package/build/src/schemas/HotDBMySQL.d.ts +65 -0
  147. package/build/src/schemas/HotDBMySQL.d.ts.map +1 -0
  148. package/build/src/schemas/HotDBMySQL.js +387 -0
  149. package/build/src/schemas/HotDBMySQL.js.map +1 -0
  150. package/build/src/schemas/HotDBSchema.d.ts +15 -0
  151. package/build/src/schemas/HotDBSchema.d.ts.map +1 -0
  152. package/build/src/schemas/HotDBSchema.js +19 -0
  153. package/build/src/schemas/HotDBSchema.js.map +1 -0
  154. package/build/src/schemas/influx/InfluxSchema.d.ts +14 -0
  155. package/build/src/schemas/influx/InfluxSchema.d.ts.map +1 -0
  156. package/build/src/schemas/influx/InfluxSchema.js +33 -0
  157. package/build/src/schemas/influx/InfluxSchema.js.map +1 -0
  158. package/build/src/schemas/mysql/MySQLSchema.d.ts +39 -0
  159. package/build/src/schemas/mysql/MySQLSchema.d.ts.map +1 -0
  160. package/build/src/schemas/mysql/MySQLSchema.js +151 -0
  161. package/build/src/schemas/mysql/MySQLSchema.js.map +1 -0
  162. package/build/src/schemas/mysql/MySQLSchemaField.d.ts +168 -0
  163. package/build/src/schemas/mysql/MySQLSchemaField.d.ts.map +1 -0
  164. package/build/src/schemas/mysql/MySQLSchemaField.js +260 -0
  165. package/build/src/schemas/mysql/MySQLSchemaField.js.map +1 -0
  166. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts +49 -0
  167. package/build/src/schemas/mysql/MySQLSchemaTable.d.ts.map +1 -0
  168. package/build/src/schemas/mysql/MySQLSchemaTable.js +310 -0
  169. package/build/src/schemas/mysql/MySQLSchemaTable.js.map +1 -0
  170. package/build-web/HotStaq.js +2 -0
  171. package/build-web/HotStaq.min.js +125 -0
  172. package/builder/docker/Dockerfile.linux.gen +42 -0
  173. package/builder/docker/README.md +36 -0
  174. package/builder/docker/app/start.sh +8 -0
  175. package/builder/docker/dockerignore +3 -0
  176. package/builder/docker/scripts/build.bat +11 -0
  177. package/builder/docker/scripts/build.sh +11 -0
  178. package/builder/docker/scripts/start-app.bat +7 -0
  179. package/builder/docker/scripts/start-app.sh +7 -0
  180. package/builder/docker/scripts/stop-app.bat +5 -0
  181. package/builder/docker/scripts/stop-app.sh +5 -0
  182. package/builder/docker-compose/docker-compose.gen.yaml +41 -0
  183. package/builder/docker-compose/env-skeleton +4 -0
  184. package/creator/project/.vscode/launch.json +59 -0
  185. package/creator/project/README.md +20 -0
  186. package/creator/project/gitignore +118 -0
  187. package/creator/project/npmignore +118 -0
  188. package/creator/public/api-test.hott +28 -0
  189. package/creator/public/index.hott +12 -0
  190. package/creator/ts/src/AppAPI.ts +30 -0
  191. package/creator/ts/src/HelloWorld.ts +39 -0
  192. package/creator/ts/src/WebExport.ts +7 -0
  193. package/creator/ts/tsconfig-web.json +73 -0
  194. package/creator/ts/tsconfig.json +73 -0
  195. package/creator/ts/webpack-api.config.js +57 -0
  196. package/dbstart.sh +19 -0
  197. package/dbstop.sh +4 -0
  198. package/docs/.nojekyll +1 -0
  199. package/docs/README.md +128 -0
  200. package/docs/classes/Hot.md +477 -0
  201. package/docs/classes/HotAPI.md +369 -0
  202. package/docs/classes/HotClient.md +95 -0
  203. package/docs/classes/HotComponent.md +279 -0
  204. package/docs/classes/HotDB.md +247 -0
  205. package/docs/classes/HotDBInflux.md +404 -0
  206. package/docs/classes/HotDBMigration.md +80 -0
  207. package/docs/classes/HotDBMySQL.md +310 -0
  208. package/docs/classes/HotDBSchema.md +51 -0
  209. package/docs/classes/HotFile.md +353 -0
  210. package/docs/classes/HotHTTPServer.md +700 -0
  211. package/docs/classes/HotLog.md +162 -0
  212. package/docs/classes/HotPage.md +357 -0
  213. package/docs/classes/HotRoute.md +312 -0
  214. package/docs/classes/HotRouteMethod.md +271 -0
  215. package/docs/classes/HotServer.md +311 -0
  216. package/docs/classes/HotStaq.md +1153 -0
  217. package/docs/classes/HotTestDestination.md +58 -0
  218. package/docs/classes/HotTestDriver.md +332 -0
  219. package/docs/classes/HotTestElement.md +88 -0
  220. package/docs/classes/HotTestElementOptions.md +71 -0
  221. package/docs/classes/HotTestMap.md +92 -0
  222. package/docs/classes/HotTestSeleniumDriver.md +529 -0
  223. package/docs/classes/HotTester.md +653 -0
  224. package/docs/classes/HotTesterAPI.md +493 -0
  225. package/docs/classes/HotTesterMocha.md +843 -0
  226. package/docs/classes/HotTesterMochaSelenium.md +896 -0
  227. package/docs/classes/HotTesterServer.md +633 -0
  228. package/docs/classes/InfluxSchema.md +74 -0
  229. package/docs/classes/MySQLSchema.md +199 -0
  230. package/docs/classes/MySQLSchemaField.md +330 -0
  231. package/docs/classes/MySQLSchemaTable.md +176 -0
  232. package/docs/enums/ConnectionStatus.md +43 -0
  233. package/docs/enums/DeveloperMode.md +38 -0
  234. package/docs/enums/EventExecutionType.md +43 -0
  235. package/docs/enums/HTTPMethod.md +32 -0
  236. package/docs/enums/HotDBGenerationType.md +30 -0
  237. package/docs/enums/HotLogLevel.md +88 -0
  238. package/docs/interfaces/HotDBConnectionInterface.md +116 -0
  239. package/docs/interfaces/HotDestination.md +62 -0
  240. package/docs/interfaces/HotSite.md +187 -0
  241. package/docs/interfaces/HotSiteMapPath.md +37 -0
  242. package/docs/interfaces/HotSiteRoute.md +79 -0
  243. package/docs/interfaces/HotStartOptions.md +115 -0
  244. package/docs/interfaces/HotTestPage.md +44 -0
  245. package/docs/interfaces/HotTestStop.md +62 -0
  246. package/docs/interfaces/IHotComponent.md +135 -0
  247. package/docs/interfaces/IHotStaq.md +118 -0
  248. package/docs/interfaces/IHotTestElement.md +54 -0
  249. package/docs/interfaces/IHotTestElementOptions.md +43 -0
  250. package/docs/interfaces/MySQLResults.md +43 -0
  251. package/docs/interfaces/MySQLSchemaFieldResult.md +75 -0
  252. package/docs/modules.md +162 -0
  253. package/package.json +65 -0
  254. package/selenium-start.sh +7 -0
  255. package/selenium-stop.sh +3 -0
  256. package/src/Hot.ts +319 -0
  257. package/src/HotAPI.ts +378 -0
  258. package/src/HotAgentAPI.ts +43 -0
  259. package/src/HotAgentRoute.ts +44 -0
  260. package/src/HotBuilder.ts +221 -0
  261. package/src/HotClient.ts +40 -0
  262. package/src/HotComponent.ts +158 -0
  263. package/src/HotCreator.ts +482 -0
  264. package/src/HotDB.ts +79 -0
  265. package/src/HotDBConnectionInterface.ts +40 -0
  266. package/src/HotFile.ts +617 -0
  267. package/src/HotHTTPServer.ts +954 -0
  268. package/src/HotIO.ts +128 -0
  269. package/src/HotLog.ts +158 -0
  270. package/src/HotPage.ts +206 -0
  271. package/src/HotRoute.ts +137 -0
  272. package/src/HotRouteMethod.ts +216 -0
  273. package/src/HotServer.ts +211 -0
  274. package/src/HotSetAsWeb.ts +3 -0
  275. package/src/HotStaq.ts +1877 -0
  276. package/src/HotStaqWeb.ts +59 -0
  277. package/src/HotTestDriver.ts +172 -0
  278. package/src/HotTestElement.ts +97 -0
  279. package/src/HotTestMap.ts +130 -0
  280. package/src/HotTestSeleniumDriver.ts +374 -0
  281. package/src/HotTester.ts +697 -0
  282. package/src/HotTesterAPI.ts +126 -0
  283. package/src/HotTesterMocha.ts +133 -0
  284. package/src/HotTesterMochaSelenium.ts +189 -0
  285. package/src/HotTesterServer.ts +551 -0
  286. package/src/api.ts +102 -0
  287. package/src/cli.ts +1147 -0
  288. package/src/schemas/HotDBInflux.ts +211 -0
  289. package/src/schemas/HotDBMigration.ts +24 -0
  290. package/src/schemas/HotDBMySQL.ts +312 -0
  291. package/src/schemas/HotDBSchema.ts +21 -0
  292. package/src/schemas/influx/InfluxSchema.ts +19 -0
  293. package/src/schemas/mysql/MySQLSchema.ts +90 -0
  294. package/src/schemas/mysql/MySQLSchemaField.ts +408 -0
  295. package/src/schemas/mysql/MySQLSchemaTable.ts +353 -0
  296. package/tsconfig-web.json +74 -0
  297. package/tsconfig.json +73 -0
  298. package/webpack.config.js +51 -0
  299. package/webpack.config.tests.js +56 -0
@@ -0,0 +1,863 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (_) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ var __importDefault = (this && this.__importDefault) || function (mod) {
73
+ return (mod && mod.__esModule) ? mod : { "default": mod };
74
+ };
75
+ Object.defineProperty(exports, "__esModule", { value: true });
76
+ exports.HotHTTPServer = void 0;
77
+ var http = __importStar(require("http"));
78
+ var https = __importStar(require("https"));
79
+ var ppath = __importStar(require("path"));
80
+ var fs = __importStar(require("fs"));
81
+ var constants_1 = require("constants");
82
+ var express_1 = __importDefault(require("express"));
83
+ var formidable_1 = require("formidable");
84
+ var HotServer_1 = require("./HotServer");
85
+ var HotStaq_1 = require("./HotStaq");
86
+ var HotRouteMethod_1 = require("./HotRouteMethod");
87
+ var HotAPI_1 = require("./HotAPI");
88
+ /**
89
+ * A HTTP server.
90
+ */
91
+ var HotHTTPServer = /** @class */ (function (_super) {
92
+ __extends(HotHTTPServer, _super);
93
+ function HotHTTPServer(processor, httpPort, httpsPort) {
94
+ if (httpPort === void 0) { httpPort = null; }
95
+ if (httpsPort === void 0) { httpsPort = null; }
96
+ var _this = _super.call(this, processor) || this;
97
+ _this.expressApp = (0, express_1.default)();
98
+ _this.httpListener = null;
99
+ _this.httpsListener = null;
100
+ _this.staticRoutes = [];
101
+ _this.routes = [];
102
+ _this.serveHottFiles = true;
103
+ _this.ignoreHottFiles = {};
104
+ _this.hottFilesAssociatedInfo = {
105
+ name: "",
106
+ url: "./",
107
+ jsSrcPath: "./js/HotStaq.js"
108
+ };
109
+ if (process.env.LISTEN_ADDR != null) {
110
+ if (process.env.LISTEN_ADDR !== "")
111
+ _this.listenAddress = process.env.LISTEN_ADDR;
112
+ }
113
+ if (process.env.USE_HTTP != null) {
114
+ _this.ssl = {
115
+ cert: "",
116
+ key: "",
117
+ ca: ""
118
+ };
119
+ }
120
+ if (httpPort != null)
121
+ _this.ports.http = httpPort;
122
+ if (httpsPort != null)
123
+ _this.ports.https = httpsPort;
124
+ if (process.env.HTTP_PORT != null) {
125
+ if (process.env.HTTP_PORT !== "")
126
+ _this.ports.http = parseInt(process.env.HTTP_PORT);
127
+ }
128
+ if (process.env.HTTPS_PORT != null) {
129
+ if (process.env.HTTPS_PORT !== "")
130
+ _this.ports.https = parseInt(process.env.HTTPS_PORT);
131
+ }
132
+ if (process.env.HTTPS_SSL_CERT != null) {
133
+ if (process.env.HTTPS_SSL_CERT !== "")
134
+ _this.ssl.cert = process.env.HTTPS_SSL_CERT;
135
+ if (process.env.HTTPS_SSL_KEY !== "")
136
+ _this.ssl.key = process.env.HTTPS_SSL_KEY;
137
+ if (process.env.HTTPS_SSL_CA !== "")
138
+ _this.ssl.ca = process.env.HTTPS_SSL_CA;
139
+ }
140
+ var JSONLimit = "1mb";
141
+ if (process.env.JSON_LIMIT != null) {
142
+ if (process.env.JSON_LIMIT !== "")
143
+ JSONLimit = process.env.JSON_LIMIT;
144
+ }
145
+ _this.expressApp.options("*", function (req, res, next) {
146
+ res.header("Access-Control-Allow-Origin", "*");
147
+ res.header("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE");
148
+ res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
149
+ res.statusCode = 204;
150
+ res.setHeader("Content-Length", "0");
151
+ res.end();
152
+ });
153
+ _this.expressApp.use(function (req, res, next) {
154
+ res.header("Access-Control-Allow-Origin", "*");
155
+ res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
156
+ next();
157
+ });
158
+ _this.expressApp.use(express_1.default.urlencoded({ "extended": true }));
159
+ _this.expressApp.use(express_1.default.json({ "limit": JSONLimit }));
160
+ return _this;
161
+ }
162
+ /**
163
+ * Add a static route.
164
+ */
165
+ HotHTTPServer.prototype.addStaticRoute = function (route, localPath) {
166
+ if (localPath === void 0) { localPath = "."; }
167
+ var staticRoute = null;
168
+ if (typeof (route) === "string") {
169
+ staticRoute = {
170
+ "route": route,
171
+ "localPath": localPath
172
+ };
173
+ }
174
+ else
175
+ staticRoute = route;
176
+ this.staticRoutes.push(staticRoute);
177
+ this.registerStaticRoute(staticRoute);
178
+ };
179
+ /**
180
+ * Add a route. This will be registered before any APIs are registered.
181
+ */
182
+ HotHTTPServer.prototype.addRoute = function (route, method, type) {
183
+ if (type === void 0) { type = HotRouteMethod_1.HTTPMethod.GET; }
184
+ var newRoute = {
185
+ type: type,
186
+ route: route,
187
+ method: method
188
+ };
189
+ this.routes.push(newRoute);
190
+ };
191
+ /**
192
+ * Serve a directory. This is an alias for addStaticRoute.
193
+ */
194
+ HotHTTPServer.prototype.serveDirectory = function (route, localPath) {
195
+ if (localPath === void 0) { localPath = "."; }
196
+ this.addStaticRoute(route, localPath);
197
+ };
198
+ /**
199
+ * Register a static route with Express.
200
+ */
201
+ HotHTTPServer.prototype.registerStaticRoute = function (route) {
202
+ this.clearErrorHandlingRoutes();
203
+ this.preregisterRoute();
204
+ this.expressApp.use(route.route, express_1.default.static(ppath.normalize(route.localPath)));
205
+ this.logger.verbose("Adding static route ".concat(route.route, " at path ").concat(route.localPath));
206
+ this.setErrorHandlingRoutes();
207
+ };
208
+ /**
209
+ * Get a static route.
210
+ */
211
+ HotHTTPServer.prototype.getStaticRoute = function (route) {
212
+ var foundRoute = null;
213
+ for (var iIdx = 0; iIdx < this.staticRoutes.length; iIdx++) {
214
+ var tempRoute = this.staticRoutes[iIdx];
215
+ if (tempRoute.route === route) {
216
+ foundRoute = tempRoute;
217
+ break;
218
+ }
219
+ }
220
+ return (foundRoute);
221
+ };
222
+ /**
223
+ * Register a route.
224
+ */
225
+ HotHTTPServer.prototype.registerRoute = function (route) {
226
+ return __awaiter(this, void 0, void 0, function () {
227
+ var _loop_1, this_1, iIdx, ex_1, msg;
228
+ var _this = this;
229
+ return __generator(this, function (_a) {
230
+ switch (_a.label) {
231
+ case 0:
232
+ _a.trys.push([0, 7, , 8]);
233
+ if (!(route.onRegister != null)) return [3 /*break*/, 2];
234
+ return [4 /*yield*/, route.onRegister()];
235
+ case 1:
236
+ if ((_a.sent()) === false)
237
+ return [2 /*return*/];
238
+ _a.label = 2;
239
+ case 2:
240
+ this.clearErrorHandlingRoutes();
241
+ this.preregisterRoute();
242
+ _loop_1 = function (iIdx) {
243
+ var method, methodName;
244
+ return __generator(this, function (_b) {
245
+ switch (_b.label) {
246
+ case 0:
247
+ method = route.methods[iIdx];
248
+ if (method.isRegistered === true)
249
+ return [2 /*return*/, "continue"];
250
+ if (!(method.onRegister != null)) return [3 /*break*/, 2];
251
+ return [4 /*yield*/, method.onRegister()];
252
+ case 1:
253
+ if ((_b.sent()) === false)
254
+ return [2 /*return*/, "continue"];
255
+ _b.label = 2;
256
+ case 2:
257
+ methodName = "/";
258
+ if (route.version !== "")
259
+ methodName += "".concat(route.version, "/");
260
+ if (route.prefix !== "")
261
+ methodName += "".concat(route.prefix, "/");
262
+ if (route.route !== "")
263
+ methodName += "".concat(route.route, "/");
264
+ methodName += method.name;
265
+ method.isRegistered = true;
266
+ this_1.logger.verbose("Adding route ".concat(method.type, " ").concat(methodName));
267
+ this_1.expressApp[method.type](methodName, function (req, res) { return __awaiter(_this, void 0, void 0, function () {
268
+ var hasAuthorization, authorizationValue, jsonObj, queryObj, api, thisObj, ex_2, ex_3, result, ex_4;
269
+ return __generator(this, function (_a) {
270
+ switch (_a.label) {
271
+ case 0:
272
+ hasAuthorization = true;
273
+ authorizationValue = null;
274
+ jsonObj = req.body;
275
+ queryObj = req.query;
276
+ api = route.connection.api;
277
+ thisObj = route;
278
+ if (api.executeEventsUsing === HotAPI_1.EventExecutionType.HotAPI)
279
+ thisObj = api;
280
+ if (api.executeEventsUsing === HotAPI_1.EventExecutionType.HotMethod)
281
+ thisObj = method;
282
+ this.logger.verbose("".concat(req.method, " ").concat(methodName, ", JSON: ").concat(JSON.stringify(jsonObj), ", Query: ").concat(JSON.stringify(queryObj)));
283
+ if (!(method.onServerAuthorize != null)) return [3 /*break*/, 5];
284
+ _a.label = 1;
285
+ case 1:
286
+ _a.trys.push([1, 3, , 4]);
287
+ return [4 /*yield*/, method.onServerAuthorize.call(thisObj, req, res, jsonObj, queryObj)];
288
+ case 2:
289
+ authorizationValue =
290
+ _a.sent();
291
+ return [3 /*break*/, 4];
292
+ case 3:
293
+ ex_2 = _a.sent();
294
+ this.logger.verbose("Authorization error: ".concat(ex_2.message));
295
+ res.json({ error: ex_2.message });
296
+ hasAuthorization = false;
297
+ return [2 /*return*/];
298
+ case 4:
299
+ if (authorizationValue === undefined)
300
+ hasAuthorization = false;
301
+ return [3 /*break*/, 10];
302
+ case 5:
303
+ if (!(route.onAuthorizeUser != null)) return [3 /*break*/, 10];
304
+ _a.label = 6;
305
+ case 6:
306
+ _a.trys.push([6, 8, , 9]);
307
+ return [4 /*yield*/, route.onAuthorizeUser(req, res)];
308
+ case 7:
309
+ authorizationValue = _a.sent();
310
+ return [3 /*break*/, 9];
311
+ case 8:
312
+ ex_3 = _a.sent();
313
+ this.logger.verbose("Authorization error: ".concat(ex_3.message));
314
+ res.json({ error: ex_3.message });
315
+ hasAuthorization = false;
316
+ return [2 /*return*/];
317
+ case 9:
318
+ if (authorizationValue === undefined)
319
+ hasAuthorization = false;
320
+ _a.label = 10;
321
+ case 10:
322
+ this.logger.verbose("".concat(req.method, " ").concat(methodName, ", Authorized: ").concat(hasAuthorization, ", Authorization Value: ").concat(authorizationValue));
323
+ if (!(hasAuthorization === true)) return [3 /*break*/, 15];
324
+ if (!(method.onServerExecute != null)) return [3 /*break*/, 14];
325
+ _a.label = 11;
326
+ case 11:
327
+ _a.trys.push([11, 13, , 14]);
328
+ return [4 /*yield*/, method.onServerExecute.call(thisObj, req, res, authorizationValue, jsonObj, queryObj)];
329
+ case 12:
330
+ result = _a.sent();
331
+ this.logger.verbose("".concat(req.method, " ").concat(methodName, ", Response: ").concat(result));
332
+ if (result !== undefined)
333
+ res.json(result);
334
+ return [3 /*break*/, 14];
335
+ case 13:
336
+ ex_4 = _a.sent();
337
+ this.logger.verbose("Execution error: ".concat(ex_4.message));
338
+ res.json({ error: ex_4.message });
339
+ return [3 /*break*/, 14];
340
+ case 14: return [3 /*break*/, 16];
341
+ case 15:
342
+ res.json(route.errors["not_authorized"]);
343
+ this.logger.verbose("".concat(req.method, " ").concat(methodName, ", not_authorized"));
344
+ _a.label = 16;
345
+ case 16: return [2 /*return*/];
346
+ }
347
+ });
348
+ }); });
349
+ return [2 /*return*/];
350
+ }
351
+ });
352
+ };
353
+ this_1 = this;
354
+ iIdx = 0;
355
+ _a.label = 3;
356
+ case 3:
357
+ if (!(iIdx < route.methods.length)) return [3 /*break*/, 6];
358
+ return [5 /*yield**/, _loop_1(iIdx)];
359
+ case 4:
360
+ _a.sent();
361
+ _a.label = 5;
362
+ case 5:
363
+ iIdx++;
364
+ return [3 /*break*/, 3];
365
+ case 6:
366
+ this.setErrorHandlingRoutes();
367
+ return [3 /*break*/, 8];
368
+ case 7:
369
+ ex_1 = _a.sent();
370
+ msg = ex_1.message;
371
+ if (ex_1.stack != null)
372
+ msg = ex_1.stack;
373
+ this.logger.error("HotHTTPServer error: ".concat(msg));
374
+ throw ex_1;
375
+ case 8: return [2 /*return*/];
376
+ }
377
+ });
378
+ });
379
+ };
380
+ /**
381
+ * Check if a file exists.
382
+ */
383
+ HotHTTPServer.checkIfFileExists = function (filepath) {
384
+ return __awaiter(this, void 0, void 0, function () {
385
+ return __generator(this, function (_a) {
386
+ switch (_a.label) {
387
+ case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
388
+ fs.access(filepath, constants_1.F_OK, function (err) {
389
+ if (err != null)
390
+ resolve(false);
391
+ resolve(true);
392
+ });
393
+ })];
394
+ case 1: return [2 /*return*/, (_a.sent())];
395
+ }
396
+ });
397
+ });
398
+ };
399
+ /**
400
+ * The routes to add before registering a route.
401
+ */
402
+ HotHTTPServer.prototype.preregisterRoute = function () {
403
+ var _this = this;
404
+ this.expressApp.use(function (req, res, next) {
405
+ var url = "".concat(req.protocol, "://").concat(req.get("host")).concat(req.originalUrl);
406
+ _this.logger.verbose("Requested: ".concat(req.method, " ").concat(req.httpVersion, " ").concat(url));
407
+ next();
408
+ });
409
+ for (var iIdx = 0; iIdx < this.routes.length; iIdx++) {
410
+ var route = this.routes[iIdx];
411
+ this.expressApp[route.type](route.route, route.method);
412
+ this.logger.verbose("Adding route ".concat(route.type, " ").concat(route.route));
413
+ }
414
+ var serveHottFiles = this.serveHottFiles;
415
+ if (this.processor.hotSite != null) {
416
+ if (this.processor.hotSite.server != null) {
417
+ if (this.processor.hotSite.server.serveHottFiles != null)
418
+ serveHottFiles = this.processor.hotSite.server.serveHottFiles;
419
+ }
420
+ if (this.processor.hotSite.routes != null) {
421
+ // Ignore any hott files from any routes. The routes will return the
422
+ // hott files themselves.
423
+ for (var key in this.processor.hotSite.routes) {
424
+ var route = this.processor.hotSite.routes[key];
425
+ var filename = ppath.basename(route.url);
426
+ this.ignoreHottFiles[filename] = true;
427
+ this.logger.verbose("Ignoring Hott file ".concat(filename));
428
+ }
429
+ }
430
+ }
431
+ if (serveHottFiles === true) {
432
+ this.logger.verbose("Set to serve hott files...");
433
+ this.expressApp.use(function (req, res, next) {
434
+ (function () { return __awaiter(_this, void 0, void 0, function () {
435
+ var bodyObj, queryObj, requestedUrl, foundUrl, url, urlFilepath, filepath, sendHottContent, result, hpserve, serveDirectories, checkDirs, iIdx, serveDir, iIdx, checkDir, route, tempFilepath, sendContentFlag;
436
+ var _this = this;
437
+ return __generator(this, function (_a) {
438
+ switch (_a.label) {
439
+ case 0:
440
+ bodyObj = req.body;
441
+ queryObj = req.query;
442
+ this.logger.verbose("Method: ".concat(req.method, " Requested URL: ").concat(req.originalUrl, " Body: ").concat(JSON.stringify(bodyObj), ", Query: ").concat(JSON.stringify(queryObj)));
443
+ requestedUrl = "".concat(req.protocol, "://").concat(req.get("host")).concat(req.originalUrl);
444
+ foundUrl = HotStaq_1.HotStaq.getValueFromHotSiteObj(this.processor.hotSite, ["server", "url"]);
445
+ if (foundUrl != null) {
446
+ if (foundUrl[(foundUrl.length - 1)] === "/")
447
+ foundUrl = foundUrl.substr(0, (foundUrl.length - 1));
448
+ requestedUrl = "".concat(foundUrl, "/").concat(req.originalUrl);
449
+ }
450
+ url = new URL(requestedUrl);
451
+ urlFilepath = url.pathname;
452
+ filepath = ppath.basename(urlFilepath);
453
+ if (!(this.ignoreHottFiles[filepath] == null)) return [3 /*break*/, 9];
454
+ sendHottContent = function (fullUrl, route) {
455
+ // Appending hpserve ensures that the content will not be resent.
456
+ fullUrl.searchParams.append("hpserve", "nahfam");
457
+ var content = _this.processor.generateContent(route, _this.hottFilesAssociatedInfo.name, fullUrl.toString(), _this.hottFilesAssociatedInfo.jsSrcPath);
458
+ // The content will be generated and sent to the client. The client
459
+ // will then request the real page that contains the file.
460
+ res.setHeader("Content-Type", "text/html");
461
+ res.send(content);
462
+ };
463
+ result = "";
464
+ hpserve = url.searchParams.get("hpserve");
465
+ if (hpserve != null)
466
+ result = hpserve;
467
+ if (!(result !== "nahfam")) return [3 /*break*/, 9];
468
+ serveDirectories = HotStaq_1.HotStaq.getValueFromHotSiteObj(this.processor.hotSite, ["server", "serveDirectories"]);
469
+ checkDirs = [];
470
+ if (serveDirectories != null) {
471
+ if (serveDirectories.length > 0) {
472
+ for (iIdx = 0; iIdx < serveDirectories.length; iIdx++) {
473
+ serveDir = serveDirectories[iIdx].localPath;
474
+ checkDirs.push(serveDir);
475
+ }
476
+ }
477
+ }
478
+ if (checkDirs.length < 1)
479
+ checkDirs.push(process.cwd());
480
+ iIdx = 0;
481
+ _a.label = 1;
482
+ case 1:
483
+ if (!(iIdx < checkDirs.length)) return [3 /*break*/, 9];
484
+ checkDir = checkDirs[iIdx];
485
+ route = urlFilepath;
486
+ tempFilepath = urlFilepath;
487
+ sendContentFlag = false;
488
+ if (!(tempFilepath.indexOf(".hott") > -1)) return [3 /*break*/, 3];
489
+ return [4 /*yield*/, HotHTTPServer.checkIfFileExists(ppath.normalize("".concat(checkDir, "/").concat(tempFilepath)))];
490
+ case 2:
491
+ if ((_a.sent()) === true) {
492
+ sendContentFlag = true;
493
+ }
494
+ _a.label = 3;
495
+ case 3:
496
+ if (!(sendContentFlag === false)) return [3 /*break*/, 5];
497
+ return [4 /*yield*/, HotHTTPServer.checkIfFileExists(ppath.normalize("".concat(checkDir, "/").concat(tempFilepath, ".hott")))];
498
+ case 4:
499
+ if ((_a.sent()) === true) {
500
+ sendContentFlag = true;
501
+ url.pathname += ".hott";
502
+ }
503
+ _a.label = 5;
504
+ case 5:
505
+ if (!(sendContentFlag === false)) return [3 /*break*/, 7];
506
+ // If no content has been found, send the index.
507
+ tempFilepath += "index.hott";
508
+ return [4 /*yield*/, HotHTTPServer.checkIfFileExists(ppath.normalize("".concat(checkDir, "/").concat(tempFilepath)))];
509
+ case 6:
510
+ if ((_a.sent()) === true) {
511
+ sendContentFlag = true;
512
+ }
513
+ _a.label = 7;
514
+ case 7:
515
+ if (tempFilepath !== urlFilepath)
516
+ url.pathname = tempFilepath;
517
+ if (sendContentFlag === true) {
518
+ sendHottContent(url, route);
519
+ return [2 /*return*/];
520
+ }
521
+ _a.label = 8;
522
+ case 8:
523
+ iIdx++;
524
+ return [3 /*break*/, 1];
525
+ case 9:
526
+ next();
527
+ return [2 /*return*/];
528
+ }
529
+ });
530
+ }); })();
531
+ });
532
+ }
533
+ };
534
+ /**
535
+ * Get all files uploaded.
536
+ */
537
+ HotHTTPServer.getFileUploads = function (req, options) {
538
+ if (options === void 0) { options = { multiples: true }; }
539
+ return __awaiter(this, void 0, void 0, function () {
540
+ return __generator(this, function (_a) {
541
+ switch (_a.label) {
542
+ case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
543
+ var form = new formidable_1.IncomingForm(options);
544
+ form.parse(req, function (err, fields, files) {
545
+ if (err != null)
546
+ throw err;
547
+ resolve(files);
548
+ });
549
+ })];
550
+ case 1: return [2 /*return*/, (_a.sent())];
551
+ }
552
+ });
553
+ });
554
+ };
555
+ /**
556
+ * Set the error handlers. This will create two express routes at the bottom of the
557
+ * route stack. The first will be to capture any 404 errors, the second would be to
558
+ * catch any remaining errors.
559
+ */
560
+ HotHTTPServer.prototype.setErrorHandlingRoutes = function (handle404, handleOther) {
561
+ var _this = this;
562
+ if (handle404 === void 0) { handle404 = null; }
563
+ if (handleOther === void 0) { handleOther = null; }
564
+ if (handle404 == null) {
565
+ handle404 = function (req, res, next) {
566
+ _this.logger.verbose("404 ".concat(JSON.stringify(req.url)));
567
+ res.status(404).send({ error: "404" });
568
+ };
569
+ }
570
+ if (handleOther == null) {
571
+ handleOther = function (err, req, res, next) {
572
+ var stack = "";
573
+ var msg = "";
574
+ if (err != null) {
575
+ stack = err.stack;
576
+ msg = err.message;
577
+ }
578
+ _this.logger.verbose("500 Server error ".concat(JSON.stringify(stack)));
579
+ res.status(500).send({ error: "Server error: ".concat(msg) });
580
+ };
581
+ }
582
+ this.expressApp.use(handle404);
583
+ this.expressApp.use(handleOther);
584
+ };
585
+ /**
586
+ * Clear the last two express routes, which are reserved for the
587
+ * error handlers.
588
+ */
589
+ HotHTTPServer.prototype.clearErrorHandlingRoutes = function () {
590
+ if (this.expressApp._router == null)
591
+ return;
592
+ var stackCount = this.expressApp._router.stack.length;
593
+ for (var iIdx = 0; iIdx < stackCount; iIdx++) {
594
+ var elm = this.expressApp._router.stack[iIdx];
595
+ if (elm != null) {
596
+ var name_1 = elm.name;
597
+ if ((name_1 === "handle404") || (name_1 === "handleOther")) {
598
+ this.expressApp._router.stack.splice(iIdx, 1);
599
+ iIdx--;
600
+ stackCount = this.expressApp._router.stack.length;
601
+ }
602
+ }
603
+ }
604
+ };
605
+ /**
606
+ * Start listening for requests.
607
+ */
608
+ HotHTTPServer.prototype.listen = function () {
609
+ return __awaiter(this, void 0, void 0, function () {
610
+ var promise;
611
+ var _this = this;
612
+ return __generator(this, function (_a) {
613
+ promise = new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
614
+ var completedSetup, hotsiteServer, iIdx, directory, iIdx, staticRoute, continueRegistering, _a, _b, _i, key, route, iIdx, method, continueOn, _c, _d, _e, key, route, iIdx, method, ex_5, msg;
615
+ var _this = this;
616
+ return __generator(this, function (_f) {
617
+ switch (_f.label) {
618
+ case 0:
619
+ _f.trys.push([0, 22, , 23]);
620
+ completedSetup = function () {
621
+ var protocol = "http";
622
+ var port = _this.ports.http;
623
+ if (_this.ssl.cert !== "") {
624
+ protocol = "https";
625
+ port = _this.ports.https;
626
+ }
627
+ _this.logger.info("".concat(_this.serverType, " running at ").concat(protocol, "://").concat(_this.listenAddress, ":").concat(port, "/"));
628
+ resolve();
629
+ };
630
+ if (this.processor.hotSite != null) {
631
+ hotsiteServer = this.processor.hotSite.server;
632
+ if (hotsiteServer != null) {
633
+ if (hotsiteServer.serveDirectories != null) {
634
+ for (iIdx = 0; iIdx < hotsiteServer.serveDirectories.length; iIdx++) {
635
+ directory = hotsiteServer.serveDirectories[iIdx];
636
+ this.staticRoutes.push({
637
+ "route": directory.route,
638
+ "localPath": ppath.normalize(directory.localPath)
639
+ });
640
+ }
641
+ }
642
+ if (hotsiteServer.ports != null) {
643
+ if (hotsiteServer.ports.http != null)
644
+ this.ports.http = hotsiteServer.ports.http;
645
+ if (hotsiteServer.ports.https != null)
646
+ this.ports.https = hotsiteServer.ports.https;
647
+ if (hotsiteServer.ports.redirectHTTPtoHTTPS != null)
648
+ this.redirectHTTPtoHTTPS = hotsiteServer.ports.redirectHTTPtoHTTPS;
649
+ }
650
+ }
651
+ }
652
+ this.processor.createExpressRoutes(this.expressApp);
653
+ for (iIdx = 0; iIdx < this.staticRoutes.length; iIdx++) {
654
+ staticRoute = this.staticRoutes[iIdx];
655
+ this.registerStaticRoute(staticRoute);
656
+ }
657
+ if (!(this.api != null)) return [3 /*break*/, 21];
658
+ if (!(this.api.onPreRegister != null)) return [3 /*break*/, 2];
659
+ return [4 /*yield*/, this.api.onPreRegister()];
660
+ case 1:
661
+ continueRegistering = _f.sent();
662
+ if (continueRegistering === false)
663
+ return [2 /*return*/];
664
+ _f.label = 2;
665
+ case 2:
666
+ _a = [];
667
+ for (_b in this.api.routes)
668
+ _a.push(_b);
669
+ _i = 0;
670
+ _f.label = 3;
671
+ case 3:
672
+ if (!(_i < _a.length)) return [3 /*break*/, 10];
673
+ key = _a[_i];
674
+ route = this.api.routes[key];
675
+ if (!(route.onPreRegister != null)) return [3 /*break*/, 5];
676
+ return [4 /*yield*/, route.onPreRegister()];
677
+ case 4:
678
+ _f.sent();
679
+ _f.label = 5;
680
+ case 5:
681
+ iIdx = 0;
682
+ _f.label = 6;
683
+ case 6:
684
+ if (!(iIdx < route.methods.length)) return [3 /*break*/, 9];
685
+ method = route.methods[iIdx];
686
+ if (!(method.onPreRegister != null)) return [3 /*break*/, 8];
687
+ return [4 /*yield*/, method.onPreRegister()];
688
+ case 7:
689
+ _f.sent();
690
+ _f.label = 8;
691
+ case 8:
692
+ iIdx++;
693
+ return [3 /*break*/, 6];
694
+ case 9:
695
+ _i++;
696
+ return [3 /*break*/, 3];
697
+ case 10:
698
+ // Register all the routes.
699
+ return [4 /*yield*/, this.api.registerRoutes()];
700
+ case 11:
701
+ // Register all the routes.
702
+ _f.sent();
703
+ if (!(this.api.onPostRegister != null)) return [3 /*break*/, 13];
704
+ return [4 /*yield*/, this.api.onPostRegister()];
705
+ case 12:
706
+ continueOn = _f.sent();
707
+ if (continueOn === false)
708
+ return [2 /*return*/];
709
+ _f.label = 13;
710
+ case 13:
711
+ _c = [];
712
+ for (_d in this.api.routes)
713
+ _c.push(_d);
714
+ _e = 0;
715
+ _f.label = 14;
716
+ case 14:
717
+ if (!(_e < _c.length)) return [3 /*break*/, 21];
718
+ key = _c[_e];
719
+ route = this.api.routes[key];
720
+ if (!(route.onPostRegister != null)) return [3 /*break*/, 16];
721
+ return [4 /*yield*/, route.onPostRegister()];
722
+ case 15:
723
+ _f.sent();
724
+ _f.label = 16;
725
+ case 16:
726
+ iIdx = 0;
727
+ _f.label = 17;
728
+ case 17:
729
+ if (!(iIdx < route.methods.length)) return [3 /*break*/, 20];
730
+ method = route.methods[iIdx];
731
+ if (!(method.onPostRegister != null)) return [3 /*break*/, 19];
732
+ return [4 /*yield*/, method.onPostRegister()];
733
+ case 18:
734
+ _f.sent();
735
+ _f.label = 19;
736
+ case 19:
737
+ iIdx++;
738
+ return [3 /*break*/, 17];
739
+ case 20:
740
+ _e++;
741
+ return [3 /*break*/, 14];
742
+ case 21:
743
+ if (this.ssl.cert === "") {
744
+ this.httpListener = http.createServer(this.expressApp);
745
+ this.httpListener.listen(this.ports.http, this.listenAddress, completedSetup);
746
+ }
747
+ else {
748
+ if (this.redirectHTTPtoHTTPS === true) {
749
+ this.httpListener = http.createServer(function (req, res) {
750
+ var host = req.headers["host"];
751
+ res.writeHead(301, {
752
+ "Location": "https://".concat(host).concat(req.url)
753
+ });
754
+ res.end();
755
+ });
756
+ this.httpListener.listen(this.ports.http, this.listenAddress, function () {
757
+ _this.logger.info("Redirecting HTTP(".concat(_this.ports.http, ") traffic to HTTPS(").concat(_this.ports.https, ")"));
758
+ });
759
+ }
760
+ this.httpsListener = https.createServer({
761
+ cert: this.ssl.cert,
762
+ key: this.ssl.key,
763
+ ca: this.ssl.ca
764
+ }, this.expressApp);
765
+ this.httpsListener.listen(this.ports.https, this.listenAddress, completedSetup);
766
+ }
767
+ return [3 /*break*/, 23];
768
+ case 22:
769
+ ex_5 = _f.sent();
770
+ msg = ex_5.message;
771
+ if (ex_5.stack != null)
772
+ msg = ex_5.stack;
773
+ this.logger.error("HotHTTPServer Error: ".concat(msg));
774
+ throw (ex_5);
775
+ case 23: return [2 /*return*/];
776
+ }
777
+ });
778
+ }); })
779
+ .catch(function (reason) {
780
+ var msg = "";
781
+ if (typeof (reason) === "string")
782
+ msg = reason;
783
+ if (reason.message != null)
784
+ msg = reason.message;
785
+ if (reason.stack != null)
786
+ msg = reason.stack;
787
+ _this.logger.error("HotHTTPServer Error: ".concat(msg));
788
+ throw reason;
789
+ });
790
+ return [2 /*return*/, (promise)];
791
+ });
792
+ });
793
+ };
794
+ /**
795
+ * Start the server.
796
+ *
797
+ * @param localStaticPath The public path that contains the HTML, Hott files, images, and
798
+ * all public content. This can also be an array of StaticRoutes.
799
+ * @param httpPort The HTTP port to listen on .
800
+ * @param httpsPort The HTTPS port to listen on.
801
+ * @param processor The HotStaq or parent server being used for communication.
802
+ */
803
+ HotHTTPServer.startServer = function (localStaticPath, httpPort, httpsPort, processor) {
804
+ if (localStaticPath === void 0) { localStaticPath = null; }
805
+ if (httpPort === void 0) { httpPort = 80; }
806
+ if (httpsPort === void 0) { httpsPort = 443; }
807
+ if (processor === void 0) { processor = null; }
808
+ return __awaiter(this, void 0, void 0, function () {
809
+ var webServer, iIdx, staticRoute;
810
+ return __generator(this, function (_a) {
811
+ switch (_a.label) {
812
+ case 0:
813
+ if (processor == null)
814
+ processor = new HotStaq_1.HotStaq();
815
+ webServer = new HotHTTPServer(processor, httpPort, httpsPort);
816
+ if (localStaticPath == null)
817
+ localStaticPath = process.cwd();
818
+ if (typeof (localStaticPath) === "string")
819
+ webServer.addStaticRoute("/", localStaticPath);
820
+ else {
821
+ for (iIdx = 0; iIdx < localStaticPath.length; iIdx++) {
822
+ staticRoute = localStaticPath[iIdx];
823
+ webServer.addStaticRoute(staticRoute);
824
+ }
825
+ }
826
+ return [4 /*yield*/, webServer.listen()];
827
+ case 1:
828
+ _a.sent();
829
+ return [2 /*return*/, ({ processor: processor, server: webServer })];
830
+ }
831
+ });
832
+ });
833
+ };
834
+ /**
835
+ * Shutdown the server.
836
+ */
837
+ HotHTTPServer.prototype.shutdown = function () {
838
+ return __awaiter(this, void 0, void 0, function () {
839
+ var _this = this;
840
+ return __generator(this, function (_a) {
841
+ switch (_a.label) {
842
+ case 0:
843
+ this.logger.verbose("Shutting down HTTP server...");
844
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
845
+ _this.httpListener.close(function (err) {
846
+ _this.expressApp = null;
847
+ if (err != null)
848
+ throw err;
849
+ _this.logger.verbose("HTTP server has shut down.");
850
+ resolve();
851
+ });
852
+ })];
853
+ case 1:
854
+ _a.sent();
855
+ return [2 /*return*/];
856
+ }
857
+ });
858
+ });
859
+ };
860
+ return HotHTTPServer;
861
+ }(HotServer_1.HotServer));
862
+ exports.HotHTTPServer = HotHTTPServer;
863
+ //# sourceMappingURL=HotHTTPServer.js.map