tungsten 0.3.2 → 0.3.3

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 (278) hide show
  1. package/dist/.build-complete +1 -0
  2. package/dist/Framework.d.ts +2 -0
  3. package/dist/Framework.d.ts.map +1 -1
  4. package/dist/Framework.js +68 -57
  5. package/dist/FrameworkConfig.d.ts +2 -0
  6. package/dist/FrameworkConfig.d.ts.map +1 -1
  7. package/dist/Instance/Instance.d.ts.map +1 -1
  8. package/dist/Instance/Instance.js +18 -1
  9. package/dist/Instance/InstanceConfig.d.ts +1 -0
  10. package/dist/Instance/InstanceConfig.d.ts.map +1 -1
  11. package/dist/PopMessage.type.d.ts +6 -0
  12. package/dist/PopMessage.type.d.ts.map +1 -0
  13. package/dist/PopMessage.type.js +1 -0
  14. package/dist/Servers/DevServer.d.ts +2 -0
  15. package/dist/Servers/DevServer.d.ts.map +1 -1
  16. package/dist/Servers/DevServer.js +84 -8
  17. package/dist/Servers/MatchedRouteInfo.d.ts +1 -1
  18. package/dist/Servers/MatchedRouteInfo.d.ts.map +1 -1
  19. package/dist/Servers/ProdServer.d.ts +1 -0
  20. package/dist/Servers/ProdServer.d.ts.map +1 -1
  21. package/dist/Servers/ProdServer.js +79 -5
  22. package/dist/Servers/hono/DevServerHono.js +25 -29
  23. package/dist/Servers/hono/ProdServerHono.js +49 -142
  24. package/dist/Servers/hono/TungstenServerHono.d.ts +1 -1
  25. package/dist/Servers/hono/TungstenServerHono.d.ts.map +1 -1
  26. package/dist/Servers/hono/TungstenServerHono.js +12 -29
  27. package/dist/Servers/routing.d.ts.map +1 -1
  28. package/dist/Servers/routing.js +10 -6
  29. package/dist/Servers/tungstenCorePrivateEnvSchema.d.ts +0 -3
  30. package/dist/Servers/tungstenCorePrivateEnvSchema.d.ts.map +1 -1
  31. package/dist/Servers/tungstenCorePrivateEnvSchema.js +3 -3
  32. package/dist/Servers/tungstenCorePublicEnvSchema.d.ts +8 -0
  33. package/dist/Servers/tungstenCorePublicEnvSchema.d.ts.map +1 -0
  34. package/dist/Servers/tungstenCorePublicEnvSchema.js +14 -0
  35. package/dist/Store/InternalStoreSchema.d.ts +2 -0
  36. package/dist/Store/InternalStoreSchema.d.ts.map +1 -1
  37. package/dist/Store/InternalStoreSchema.js +1 -0
  38. package/dist/api/Request.d.ts +1 -1
  39. package/dist/api/Request.d.ts.map +1 -1
  40. package/dist/api/Response.d.ts +1 -1
  41. package/dist/api/Response.d.ts.map +1 -1
  42. package/dist/babelPlugins/BabelTypes.d.ts +2 -2
  43. package/dist/babelPlugins/BabelTypes.d.ts.map +1 -1
  44. package/dist/babelPlugins/BabelTypes.js +0 -1
  45. package/dist/bin/commands/build.d.ts.map +1 -1
  46. package/dist/bin/commands/build.js +3 -0
  47. package/dist/bin/commands/dev.d.ts.map +1 -1
  48. package/dist/bin/commands/dev.js +15 -4
  49. package/dist/bin/commands/devmon.d.ts +2 -0
  50. package/dist/bin/commands/devmon.d.ts.map +1 -0
  51. package/dist/bin/commands/devmon.js +66 -0
  52. package/dist/bin/index.d.ts.map +1 -1
  53. package/dist/bin/index.js +6 -0
  54. package/dist/booleanAttributeValue.d.ts +21 -0
  55. package/dist/booleanAttributeValue.d.ts.map +1 -0
  56. package/dist/booleanAttributeValue.js +23 -0
  57. package/dist/build/compileJavascript.js +1 -1
  58. package/dist/build/compileUserApp.d.ts +2 -1
  59. package/dist/build/compileUserApp.d.ts.map +1 -1
  60. package/dist/build/compileUserApp.js +8 -7
  61. package/dist/build/createInstanceConfigFile.js +1 -1
  62. package/dist/compat/types.d.ts +1 -1
  63. package/dist/compat/types.d.ts.map +1 -1
  64. package/dist/components/PopMessages.d.ts +12 -0
  65. package/dist/components/PopMessages.d.ts.map +1 -0
  66. package/dist/components/PopMessages.js +45 -0
  67. package/dist/defaultConfig.d.ts +1 -0
  68. package/dist/defaultConfig.d.ts.map +1 -1
  69. package/dist/defaultConfig.js +2 -1
  70. package/dist/env/Interfaces.d.ts +2 -1
  71. package/dist/env/Interfaces.d.ts.map +1 -1
  72. package/dist/env/getEnvSchemas.d.ts +1 -1
  73. package/dist/env/getEnvSchemas.d.ts.map +1 -1
  74. package/dist/env/publicEnv.d.ts.map +1 -1
  75. package/dist/env/publicEnv.js +4 -1
  76. package/dist/frameworkConfigSchema.d.ts +4 -0
  77. package/dist/frameworkConfigSchema.d.ts.map +1 -1
  78. package/dist/frameworkConfigSchema.js +2 -1
  79. package/dist/hooks/index.d.ts +1 -0
  80. package/dist/hooks/index.d.ts.map +1 -1
  81. package/dist/hooks/index.js +1 -0
  82. package/dist/hooks/useInstance.d.ts +3 -0
  83. package/dist/hooks/useInstance.d.ts.map +1 -0
  84. package/dist/hooks/useInstance.js +4 -0
  85. package/dist/hydrate/hydrate.d.ts +6 -4
  86. package/dist/hydrate/hydrate.d.ts.map +1 -1
  87. package/dist/hydrate/hydrate.js +51 -13
  88. package/dist/hydrate/reconcileHydratedAttributes.d.ts.map +1 -1
  89. package/dist/hydrate/reconcileHydratedAttributes.js +4 -3
  90. package/dist/hydrate/renderHydrationMismatchBanner.d.ts +7 -0
  91. package/dist/hydrate/renderHydrationMismatchBanner.d.ts.map +1 -0
  92. package/dist/hydrate/renderHydrationMismatchBanner.js +69 -0
  93. package/dist/indexInner.d.ts +8 -0
  94. package/dist/indexInner.d.ts.map +1 -1
  95. package/dist/indexInner.js +7 -1
  96. package/dist/makeInstanceConfigFromFrameworkConfig.d.ts.map +1 -1
  97. package/dist/makeInstanceConfigFromFrameworkConfig.js +2 -1
  98. package/dist/pop.d.ts +10 -0
  99. package/dist/pop.d.ts.map +1 -0
  100. package/dist/pop.js +49 -0
  101. package/dist/rawHtml/filterContentNode.d.ts +20 -0
  102. package/dist/rawHtml/filterContentNode.d.ts.map +1 -0
  103. package/dist/rawHtml/filterContentNode.js +96 -0
  104. package/dist/rawHtml/parseHtml.d.ts +14 -0
  105. package/dist/rawHtml/parseHtml.d.ts.map +1 -1
  106. package/dist/rawHtml/parseHtml.js +4 -4
  107. package/dist/rawHtml/sanitizeHtml.d.ts +17 -0
  108. package/dist/rawHtml/sanitizeHtml.d.ts.map +1 -0
  109. package/dist/rawHtml/sanitizeHtml.js +19 -0
  110. package/dist/render/HeadData.d.ts +1 -0
  111. package/dist/render/HeadData.d.ts.map +1 -1
  112. package/dist/render/contentNodeToHtml.d.ts +18 -0
  113. package/dist/render/contentNodeToHtml.d.ts.map +1 -0
  114. package/dist/render/contentNodeToHtml.js +66 -0
  115. package/dist/render/contentToHtml.d.ts.map +1 -1
  116. package/dist/render/contentToHtml.js +2 -1
  117. package/dist/render/processHead.d.ts.map +1 -1
  118. package/dist/render/processHead.js +8 -2
  119. package/dist/render/renderingTreeToHtml.d.ts.map +1 -1
  120. package/dist/render/renderingTreeToHtml.js +8 -1
  121. package/dist/routing/ErrorRouteType.d.ts +6 -0
  122. package/dist/routing/ErrorRouteType.d.ts.map +1 -0
  123. package/dist/routing/ErrorRouteType.js +1 -0
  124. package/dist/routing/RouteTypes.d.ts +2 -1
  125. package/dist/routing/RouteTypes.d.ts.map +1 -1
  126. package/dist/routing/Routes.d.ts +5 -0
  127. package/dist/routing/Routes.d.ts.map +1 -1
  128. package/dist/routing/TungstenErrorInfo.d.ts +6 -0
  129. package/dist/routing/TungstenErrorInfo.d.ts.map +1 -0
  130. package/dist/routing/TungstenErrorInfo.js +6 -0
  131. package/dist/style/styleContentSxy.js +21 -0
  132. package/dist/testing/hydrateTestApp.d.ts +38 -0
  133. package/dist/testing/hydrateTestApp.d.ts.map +1 -0
  134. package/dist/testing/hydrateTestApp.js +242 -0
  135. package/dist/testing/index.d.ts +4 -3
  136. package/dist/testing/index.d.ts.map +1 -1
  137. package/dist/testing/index.js +16 -2
  138. package/dist/timeProfiler.d.ts +6 -0
  139. package/dist/timeProfiler.d.ts.map +1 -0
  140. package/dist/timeProfiler.js +31 -0
  141. package/dist/update/integrateUpdateVdom.d.ts +11 -0
  142. package/dist/update/integrateUpdateVdom.d.ts.map +1 -1
  143. package/dist/update/integrateUpdateVdom.js +9 -3
  144. package/dist/warnOnFrameworkChange.d.ts.map +1 -1
  145. package/dist/warnOnFrameworkChange.js +8 -8
  146. package/package.json +18 -16
  147. package/dist/FunctionComponentStandIn.sxyt.d.ts +0 -2
  148. package/dist/FunctionComponentStandIn.sxyt.d.ts.map +0 -1
  149. package/dist/FunctionComponentStandIn.sxyt.js +0 -52
  150. package/dist/Instance/gotoRedirect.sxyt.d.ts +0 -2
  151. package/dist/Instance/gotoRedirect.sxyt.d.ts.map +0 -1
  152. package/dist/Instance/gotoRedirect.sxyt.js +0 -148
  153. package/dist/Instance/runTrackedWork.sxyt.d.ts +0 -2
  154. package/dist/Instance/runTrackedWork.sxyt.d.ts.map +0 -1
  155. package/dist/Instance/runTrackedWork.sxyt.js +0 -35
  156. package/dist/Servers/devErrorPageAutoRetry.sxyt.d.ts +0 -2
  157. package/dist/Servers/devErrorPageAutoRetry.sxyt.d.ts.map +0 -1
  158. package/dist/Servers/devErrorPageAutoRetry.sxyt.js +0 -117
  159. package/dist/_client/cjsHelpers.sxyt.d.ts +0 -2
  160. package/dist/_client/cjsHelpers.sxyt.d.ts.map +0 -1
  161. package/dist/_client/cjsHelpers.sxyt.js +0 -45
  162. package/dist/auth/passwordHashing.sxyt.d.ts +0 -2
  163. package/dist/auth/passwordHashing.sxyt.d.ts.map +0 -1
  164. package/dist/auth/passwordHashing.sxyt.js +0 -46
  165. package/dist/auth/ref/checkPasswordResetToken.sxyt.d.ts +0 -2
  166. package/dist/auth/ref/checkPasswordResetToken.sxyt.d.ts.map +0 -1
  167. package/dist/auth/ref/checkPasswordResetToken.sxyt.js +0 -40
  168. package/dist/auth/ref/createPasswordResetToken.sxyt.d.ts +0 -2
  169. package/dist/auth/ref/createPasswordResetToken.sxyt.d.ts.map +0 -1
  170. package/dist/auth/ref/createPasswordResetToken.sxyt.js +0 -10
  171. package/dist/babelPlugins/BabelAddDevCacheBust.sxyt.d.ts +0 -2
  172. package/dist/babelPlugins/BabelAddDevCacheBust.sxyt.d.ts.map +0 -1
  173. package/dist/babelPlugins/BabelAddDevCacheBust.sxyt.js +0 -138
  174. package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.d.ts +0 -2
  175. package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.d.ts.map +0 -1
  176. package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.js +0 -108
  177. package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.d.ts +0 -2
  178. package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.d.ts.map +0 -1
  179. package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.js +0 -104
  180. package/dist/bin/commands/compile.sxyt.d.ts +0 -2
  181. package/dist/bin/commands/compile.sxyt.d.ts.map +0 -1
  182. package/dist/bin/commands/compile.sxyt.js +0 -255
  183. package/dist/build/modifySassImports.sxyt.d.ts +0 -2
  184. package/dist/build/modifySassImports.sxyt.d.ts.map +0 -1
  185. package/dist/build/modifySassImports.sxyt.js +0 -55
  186. package/dist/build/sassImportParser.sxyt.d.ts +0 -2
  187. package/dist/build/sassImportParser.sxyt.d.ts.map +0 -1
  188. package/dist/build/sassImportParser.sxyt.js +0 -110
  189. package/dist/build/scssImportParserChatgpt.sxyt.d.ts +0 -2
  190. package/dist/build/scssImportParserChatgpt.sxyt.d.ts.map +0 -1
  191. package/dist/build/scssImportParserChatgpt.sxyt.js +0 -120
  192. package/dist/clone.sxyt.d.ts +0 -2
  193. package/dist/clone.sxyt.d.ts.map +0 -1
  194. package/dist/clone.sxyt.js +0 -24
  195. package/dist/componentProxyHandlers.sxyt.d.ts +0 -2
  196. package/dist/componentProxyHandlers.sxyt.d.ts.map +0 -1
  197. package/dist/componentProxyHandlers.sxyt.js +0 -130
  198. package/dist/components/RawHtml.sxyt.d.ts +0 -2
  199. package/dist/components/RawHtml.sxyt.d.ts.map +0 -1
  200. package/dist/components/RawHtml.sxyt.js +0 -104
  201. package/dist/components/bindable/BindableSelect.sxyt.d.ts +0 -2
  202. package/dist/components/bindable/BindableSelect.sxyt.d.ts.map +0 -1
  203. package/dist/components/bindable/BindableSelect.sxyt.js +0 -186
  204. package/dist/env/injectEnv.sxyt.d.ts +0 -2
  205. package/dist/env/injectEnv.sxyt.d.ts.map +0 -1
  206. package/dist/env/injectEnv.sxyt.js +0 -20
  207. package/dist/env/parseEnv.sxyt.d.ts +0 -2
  208. package/dist/env/parseEnv.sxyt.d.ts.map +0 -1
  209. package/dist/env/parseEnv.sxyt.js +0 -11
  210. package/dist/findProjectDir.sxyt.d.ts +0 -2
  211. package/dist/findProjectDir.sxyt.d.ts.map +0 -1
  212. package/dist/findProjectDir.sxyt.js +0 -82
  213. package/dist/hmr/applyHmrModule.sxyt.d.ts +0 -2
  214. package/dist/hmr/applyHmrModule.sxyt.d.ts.map +0 -1
  215. package/dist/hmr/applyHmrModule.sxyt.js +0 -182
  216. package/dist/hmr/instanceRegistry.sxyt.d.ts +0 -2
  217. package/dist/hmr/instanceRegistry.sxyt.d.ts.map +0 -1
  218. package/dist/hmr/instanceRegistry.sxyt.js +0 -24
  219. package/dist/hmr/refreshStylesheets.sxyt.d.ts +0 -2
  220. package/dist/hmr/refreshStylesheets.sxyt.d.ts.map +0 -1
  221. package/dist/hmr/refreshStylesheets.sxyt.js +0 -46
  222. package/dist/hydrate/hydrate.sxyt.d.ts +0 -2
  223. package/dist/hydrate/hydrate.sxyt.d.ts.map +0 -1
  224. package/dist/hydrate/hydrate.sxyt.js +0 -302
  225. package/dist/hydrate/reconcileHydratedAttributes.sxyt.d.ts +0 -2
  226. package/dist/hydrate/reconcileHydratedAttributes.sxyt.d.ts.map +0 -1
  227. package/dist/hydrate/reconcileHydratedAttributes.sxyt.js +0 -190
  228. package/dist/importDevModuleWithRetry.sxyt.d.ts +0 -2
  229. package/dist/importDevModuleWithRetry.sxyt.d.ts.map +0 -1
  230. package/dist/importDevModuleWithRetry.sxyt.js +0 -104
  231. package/dist/innerHtmlFromProps.sxyt.d.ts +0 -2
  232. package/dist/innerHtmlFromProps.sxyt.d.ts.map +0 -1
  233. package/dist/innerHtmlFromProps.sxyt.js +0 -99
  234. package/dist/postcssPlugins/parseSelectors.sxyt.d.ts +0 -2
  235. package/dist/postcssPlugins/parseSelectors.sxyt.d.ts.map +0 -1
  236. package/dist/postcssPlugins/parseSelectors.sxyt.js +0 -62
  237. package/dist/postcssPlugins/parseSelectorsRich.sxyt.d.ts +0 -2
  238. package/dist/postcssPlugins/parseSelectorsRich.sxyt.d.ts.map +0 -1
  239. package/dist/postcssPlugins/parseSelectorsRich.sxyt.js +0 -155
  240. package/dist/rawHtml/parseHtml.sxyt.d.ts +0 -2
  241. package/dist/rawHtml/parseHtml.sxyt.d.ts.map +0 -1
  242. package/dist/rawHtml/parseHtml.sxyt.js +0 -239
  243. package/dist/render/getFunctionBodyAsString.sxyt.d.ts +0 -2
  244. package/dist/render/getFunctionBodyAsString.sxyt.d.ts.map +0 -1
  245. package/dist/render/getFunctionBodyAsString.sxyt.js +0 -37
  246. package/dist/render/processHead.sxyt.d.ts +0 -2
  247. package/dist/render/processHead.sxyt.d.ts.map +0 -1
  248. package/dist/render/processHead.sxyt.js +0 -93
  249. package/dist/render/processProps.sxyt.d.ts +0 -2
  250. package/dist/render/processProps.sxyt.d.ts.map +0 -1
  251. package/dist/render/processProps.sxyt.js +0 -90
  252. package/dist/routing/compareRequestToRegex.sxyt.d.ts +0 -2
  253. package/dist/routing/compareRequestToRegex.sxyt.d.ts.map +0 -1
  254. package/dist/routing/compareRequestToRegex.sxyt.js +0 -65
  255. package/dist/routing/getPathPriority.sxyt.d.ts +0 -2
  256. package/dist/routing/getPathPriority.sxyt.d.ts.map +0 -1
  257. package/dist/routing/getPathPriority.sxyt.js +0 -24
  258. package/dist/routing/matchPath.sxyt.d.ts +0 -2
  259. package/dist/routing/matchPath.sxyt.d.ts.map +0 -1
  260. package/dist/routing/matchPath.sxyt.js +0 -41
  261. package/dist/routing/patternToRegex.sxyt.d.ts +0 -2
  262. package/dist/routing/patternToRegex.sxyt.d.ts.map +0 -1
  263. package/dist/routing/patternToRegex.sxyt.js +0 -69
  264. package/dist/routing/splitRequest.sxyt.d.ts +0 -2
  265. package/dist/routing/splitRequest.sxyt.d.ts.map +0 -1
  266. package/dist/routing/splitRequest.sxyt.js +0 -47
  267. package/dist/style/jssToCss.sxyt.d.ts +0 -2
  268. package/dist/style/jssToCss.sxyt.d.ts.map +0 -1
  269. package/dist/style/jssToCss.sxyt.js +0 -17
  270. package/dist/testing/createTestApp.sxyt.d.ts +0 -2
  271. package/dist/testing/createTestApp.sxyt.d.ts.map +0 -1
  272. package/dist/testing/createTestApp.sxyt.js +0 -470
  273. package/dist/testing/ensureTestEnvLoaded.sxyt.d.ts +0 -2
  274. package/dist/testing/ensureTestEnvLoaded.sxyt.d.ts.map +0 -1
  275. package/dist/testing/ensureTestEnvLoaded.sxyt.js +0 -20
  276. package/dist/update/hotSwap.sxyt.d.ts +0 -2
  277. package/dist/update/hotSwap.sxyt.d.ts.map +0 -1
  278. package/dist/update/hotSwap.sxyt.js +0 -252
@@ -19,6 +19,7 @@ import { globalDataFunc } from "../routing/registerGlobalData.js";
19
19
  import { TungstenServer } from "./TungstenServer.js";
20
20
  import { portError } from "./portError.js";
21
21
  import { initStores } from "./initStores.js";
22
+ import { makeTungstenErrorInfo } from "../routing/TungstenErrorInfo.js";
22
23
  function debug(...texts) {
23
24
  // console.log(...texts)
24
25
  }
@@ -83,6 +84,14 @@ export class ProdServer extends TungstenServer {
83
84
  res.status(404).end();
84
85
  return;
85
86
  }
87
+ // Captured as soon as it resolves, independent of the Promise.all below - that's
88
+ // all-or-nothing, so if routing/route-data-fetching fails afterwards, `globalData`
89
+ // never gets assigned even though fetching it didn't fail (global data and route data
90
+ // are independent tRPC calls, batched together but not coupled - see
91
+ // resolveResponse.ts in @trpc/server). tryRenderErrorRoute uses this to render the
92
+ // app's error route with the real global data (theme colour, username, ...) rather
93
+ // than framework defaults, when it did resolve.
94
+ let capturedGlobalData = {};
86
95
  try {
87
96
  const location = req.url;
88
97
  const instanceConfig = makeInstanceConfigFromFrameworkConfig(this.config);
@@ -115,7 +124,10 @@ export class ProdServer extends TungstenServer {
115
124
  value: false
116
125
  };
117
126
  const routes = typeof appRoutes === 'function' ? appRoutes(reqRes) : appRoutes;
118
- const [globalData, matchedRouteInfo] = await Promise.all([globalDataFunc.value !== undefined ? globalDataFunc.value(reqRes) : {}, routing(location, routes, serverDataLoading)]);
127
+ const [globalData, matchedRouteInfo] = await Promise.all([globalDataFunc.value !== undefined ? globalDataFunc.value(reqRes).then(globalData => {
128
+ capturedGlobalData = globalData;
129
+ return globalData;
130
+ }) : {}, routing(location, routes, serverDataLoading)]);
119
131
  //instance.matchedRouteInfo =
120
132
  //cliTodo('Can we move redirect handling to base class?')
121
133
  // // 2025-03-14 copied this code here from Dev server,
@@ -165,14 +177,76 @@ export class ProdServer extends TungstenServer {
165
177
  res.send(html);
166
178
  } catch (e) {
167
179
  cliLog('handleRequest() error', e);
180
+ const errorRouteHtml = await this.tryRenderErrorRoute(req, res, capturedGlobalData, e);
168
181
  res.setHeader('Content-Type', 'text/html');
169
182
  res.status(500);
170
- res.send(this.errorPage());
183
+ res.send(errorRouteHtml ?? this.errorPage());
184
+ }
185
+ });
186
+ // Attempts to render the app's own 'error' route in place of the framework's generic
187
+ // error page, using whatever `globalData` handleRequest above managed to capture before
188
+ // it failed (see the capturedGlobalData comment there for why that's not always {}). Only
189
+ // usable when the app routes themselves could be resolved (this runs from the catch block
190
+ // of handleRequest, so anything from route resolution onward may have failed) and the app
191
+ // actually defines an 'error' route. Never throws - falls back to null (the caller's
192
+ // default error page) on any failure, since we're already handling one error and can't
193
+ // risk a second, unhandled one taking the server down.
194
+ _defineProperty(this, "tryRenderErrorRoute", async (req, res, globalData, error) => {
195
+ try {
196
+ if (this.framework.clientImportAliases === undefined) {
197
+ throwError('ProdServer.tryRenderErrorRoute()', 'framework.clientImportAliases is undefined');
198
+ }
199
+ const {
200
+ config,
201
+ appRoutes,
202
+ RootComponentOrNull
203
+ } = this;
204
+ const reqRes = {
205
+ req,
206
+ res
207
+ };
208
+ const routes = typeof appRoutes === 'function' ? appRoutes(reqRes) : appRoutes;
209
+ const errorRouteDef = routes.error;
210
+ if (errorRouteDef === undefined) return null;
211
+ const location = req.url;
212
+ const instanceConfig = makeInstanceConfigFromFrameworkConfig(this.config);
213
+ const matchedRouteInfo = {
214
+ key: 'error',
215
+ params: {},
216
+ content: errorRouteDef.content,
217
+ data: makeTungstenErrorInfo(error)
218
+ };
219
+ const serverDataLoading = {
220
+ value: false
221
+ };
222
+ const {
223
+ internalStore,
224
+ stores,
225
+ storeSubscriptions
226
+ } = initStores(location, reqRes, globalData, matchedRouteInfo, serverDataLoading);
227
+ const instance = new Instance(location, instanceConfig, reqRes, appRoutes, routes, internalStore, stores, storeSubscriptions, globalData, matchedRouteInfo);
228
+ if (RootComponentOrNull !== null) {
229
+ return await renderRootToHtml(this.compilationInfo, this.framework.clientImportAliases, RootComponentOrNull, instance, config, this.config.siteBasePath);
230
+ }
231
+ const {
232
+ params,
233
+ data
234
+ } = matchedRouteInfo;
235
+ let {
236
+ content
237
+ } = matchedRouteInfo;
238
+ if (typeof content === 'function') {
239
+ content = content(data, params, {} /* props */, globalData, location);
240
+ }
241
+ return await renderContentToHtml(this.compilationInfo, this.framework.clientImportAliases, content, instance, config, this.config.siteBasePath);
242
+ } catch (renderError) {
243
+ cliLog('Error rendering app error route, falling back to default error page', renderError);
244
+ return null;
171
245
  }
172
246
  });
173
247
  _defineProperty(this, "errorPage", () => {
174
248
  return `<!DOCTYPE html>
175
- </html>
249
+ <html>
176
250
  <head><title>Error</title></head>
177
251
  <body>
178
252
  <h1>Internal error</h1>
@@ -263,8 +337,8 @@ export class ProdServer extends TungstenServer {
263
337
  // I don't think we ever override the port, not sure why
264
338
  start(portOverride, mute = false) {
265
339
  return new Promise(resolve => {
266
- const proto = tungstenPrivateEnv.FRONTEND_PROTO ?? 'http';
267
- const host = tungstenPrivateEnv.FRONTEND_HOST ?? 'localhost';
340
+ const proto = tungstenPublicEnv.FRONTEND_PROTO ?? 'http';
341
+ const host = tungstenPublicEnv.FRONTEND_HOST ?? 'localhost';
268
342
  let port;
269
343
  if (portOverride !== undefined) {
270
344
  port = portOverride;
@@ -1,8 +1,7 @@
1
- // import type { Server } from 'http'
2
- // //import express, { Request, Response, NextFunction, RequestHandler } from 'express'
1
+ // Status/known gaps: see ./README.md
3
2
  // import { Context, Hono } from 'hono'
4
3
  // import type { BlankEnv, BlankSchema, Handler, Next } from 'hono/types'
5
- // import { serve } from '@hono/node-server'
4
+ // import { serve, type ServerType } from '@hono/node-server'
6
5
  // import { serveStatic } from '@hono/node-server/serve-static'
7
6
  // import { join } from 'path'
8
7
  // import { allObj as promiseAllObj } from 'sxy-lib/promises.js'
@@ -35,7 +34,6 @@
35
34
  // import { ServerDataLoading } from '../../Store/ServerDataLoading.js'
36
35
  // import { TungstenServer } from '../TungstenServer.jsx'
37
36
  // import { Routes } from '../../routing/Routes.js'
38
- // import { RedirectCode, RoutingRedirect } from '../../routing/RoutingRedirect.js'
39
37
  // import { portError } from '../portError.js'
40
38
  // import { loadEnvsDev } from '../loadEnvsDev.js'
41
39
  // import { initStores } from '../initStores.js'
@@ -45,7 +43,6 @@
45
43
  // import { MatchedRoute } from '../../routing/MatchedRoute.js'
46
44
  // import { ContentNodeIsClassComponent } from '../../ContentNode.js'
47
45
  // import { $props, $type } from '../../contentNodeSymbols.js'
48
- // import { RedirectComponent } from '../../components/RedirectComponent.js'
49
46
  // import { Path } from '../../routing/RouteTypes.js'
50
47
  // import type { ApiRoutesHono } from '../../api/ApiRoutesHono.js'
51
48
  // import { TungstenServerHono } from './TungstenServerHono.jsx'
@@ -64,9 +61,10 @@ export {};
64
61
  // app: Hono<BlankEnv, BlankSchema, '/'>
65
62
  // apiRoutes?: ApiRoutesHono
66
63
  // apiPath?: string
67
- // server?: Server
64
+ // server?: ServerType
68
65
  // reqId: number
69
66
  // firstRender: boolean = true
67
+ // iterationCount: number = 0
70
68
  // constructor(
71
69
  // framework: Framework, config: FrameworkConfigComplete, compilationInfo: CompilationInfo,
72
70
  // initialProcessEnv: Record<string, string> = {}/* FIX ME */
@@ -83,8 +81,8 @@ export {};
83
81
  // // + '\n Ensure that you have an env schema with this field, and a matching env file'
84
82
  // // )
85
83
  // // }
86
- // const proto = tungstenPrivateEnv.FRONTEND_PROTO ?? 'http'
87
- // const host = tungstenPrivateEnv.FRONTEND_HOST ?? 'localhost'
84
+ // const proto = tungstenPublicEnv.FRONTEND_PROTO ?? 'http'
85
+ // const host = tungstenPublicEnv.FRONTEND_HOST ?? 'localhost'
88
86
  // const port = tungstenPrivateEnv.TUNGSTEN_SERVER_PORT ?? 3000
89
87
  // if (isNaN(port) || port === 0) throwError('DevServer', portError(port))
90
88
  // this.port = port
@@ -301,21 +299,24 @@ export {};
301
299
  // )
302
300
  // }
303
301
  // globalDataFunc.value = undefined
304
- // const load = await createLoad(import.meta.url, sxyLoaderConfig)
305
- // await loadEnvsDev(this.config, load, this.initialProcessEnv, false)
306
- // // we are delaying instance creation until after we load the app code, to lets things initialise?
307
- // //const reqRes: ReqRes = { req, res }
308
- // //const honoContext = c
302
+ // const iteration = this.iterationCount++
303
+ // await loadEnvsDev(this.config, iteration, this.initialProcessEnv, false)
304
+ // // ReqRes is Express-shaped ({req, res}) and Hono's Context isn't - this cast is a
305
+ // // type-only bridge so the (Express-only) Instance/initStores/routing plumbing below
306
+ // // still compiles. Not behaviorally correct; fine since this dev server isn't wired
307
+ // // up anywhere live (see Framework.createDevServer, which only builds DevServer).
308
+ // // eslint-disable-next-line no-type-assertion/no-type-assertion -- see comment above
309
+ // const reqRes = c as unknown as ReqRes
309
310
  // // Save some state. I think this is a placeholder for later
310
311
  // const serverDataLoading: ServerDataLoading = { value: false }
311
- // const routingPromise = getRoutesDev(this.compilationInfo, this.config, load).then(
312
+ // const routingPromise = getRoutesDev(this.compilationInfo, this.config, iteration).then(
312
313
  // async (appRoutes) => {
313
- // const routes = (typeof appRoutes === 'function') ? appRoutes(c) : appRoutes
314
+ // const routes = (typeof appRoutes === 'function') ? appRoutes(reqRes) : appRoutes
314
315
  // // load data, and do routing
315
316
  // return promiseAllObj({
316
317
  // appRoutes,
317
318
  // routes,
318
- // globalData: (globalDataFunc.value !== undefined) ? globalDataFunc.value(c) : {},
319
+ // globalData: (globalDataFunc.value !== undefined) ? globalDataFunc.value(reqRes) : {},
319
320
  // matchedRouteInfo: routing(location, routes, serverDataLoading)
320
321
  // })
321
322
  // }
@@ -330,7 +331,7 @@ export {};
330
331
  // ;({ routing: { appRoutes, routes, globalData, matchedRouteInfo }, RootComponentClass }
331
332
  // = await promiseAllObj({
332
333
  // routing: routingPromise,
333
- // RootComponentClass: getComponentDev(rootComponentFileFull, this.config.rootComponent, load)
334
+ // RootComponentClass: getComponentDev(rootComponentFileFull, this.config.rootComponent, iteration)
334
335
  // }))
335
336
  // } else {
336
337
  // ({ appRoutes, routes, globalData, matchedRouteInfo } = await routingPromise)
@@ -344,13 +345,13 @@ export {};
344
345
  // // routing(location, routes, serverDataLoading)
345
346
  // // ])
346
347
  // const redirected = this.handleRedirects(c, matchedRouteInfo)
347
- // if (redirected) return // end early
348
+ // if (redirected !== false) return redirected // end early
348
349
  // // make stores
349
350
  // const { internalStore, stores, storeSubscriptions }
350
- // = initStores(location, c, globalData, matchedRouteInfo, serverDataLoading)
351
+ // = initStores(location, reqRes, globalData, matchedRouteInfo, serverDataLoading)
351
352
  // // create the instance
352
- // const instance = new Instance(
353
- // location, instanceConfig, c, appRoutes, routes, internalStore,
353
+ // const instance = new Instance(
354
+ // location, instanceConfig, reqRes, appRoutes, routes, internalStore,
354
355
  // stores, storeSubscriptions, globalData, matchedRouteInfo
355
356
  // )
356
357
  // let html: string
@@ -379,16 +380,11 @@ export {};
379
380
  // // '' // siteBasePathOverride
380
381
  // // )
381
382
  // }
382
- // //debug('html', html)
383
- // res.setHeader('Content-Type', 'text/html')
384
- // res.status((instance.matchedRouteInfo.key === '404') ? 404 : 200)
385
- // res.send(html)
383
+ // return c.html(html, (instance.matchedRouteInfo.key === '404') ? 404 : 200)
386
384
  // } catch(e) {
387
385
  // cliLog('error', e)
388
- // res.setHeader('Content-Type', 'text/html')
389
- // res.status(500)
390
386
  // this.errorLog(e)
391
- // res.send(this.errorPage(e))
387
+ // return c.html(this.errorPage(e), 500)
392
388
  // }
393
389
  // }
394
390
  // // private async handlePost(req: express.Request, res: express.Response): Promise<void> {
@@ -414,7 +410,7 @@ export {};
414
410
  // }
415
411
  // start = (): Promise<string> => {
416
412
  // return new Promise( resolve => {
417
- // this.server = this.app.listen(this.port, () => {
413
+ // this.server = serve({ fetch: this.app.fetch, port: this.port }, () => {
418
414
  // cliNews(`Dev server ready at ${this.location}`)
419
415
  // resolve(this.location ?? '')
420
416
  // })
@@ -1,11 +1,9 @@
1
- // import type { AddressInfo } from 'net'
2
- // //import express from 'express'
3
- // import { Hono } from 'hono'
4
- // import { serve } from '@hono/node-server'
5
- // import { Server } from 'http'
1
+ // Status/known gaps: see ./README.md
2
+ // import { Context, Hono } from 'hono'
3
+ // import { serve, type ServerType } from '@hono/node-server'
4
+ // import { serveStatic } from '@hono/node-server/serve-static'
6
5
  // import { join } from 'path'
7
6
  // import { existsSync } from 'fs'
8
- // //import { SxyServer } from './SxyServer.js'
9
7
  // import type { FrameworkConfigComplete } from '../../FrameworkConfig.js'
10
8
  // import type { CompilationInfo } from '../../build/CompilationInfo.js'
11
9
  // import type { ApiRoutes } from '../../api/ApiRoutes.js'
@@ -17,7 +15,6 @@
17
15
  // import { Framework } from '../../Framework.js'
18
16
  // import { TungstenError } from '../../TungstenError.js'
19
17
  // import { makeInstanceConfigFromFrameworkConfig } from '../../makeInstanceConfigFromFrameworkConfig.js'
20
- // //import { addRequireResolveHooks } from '../reRouting/addRequireResolveHooks.js'
21
18
  // import { standardizeWebPath } from '../../standardizeWebPath.js'
22
19
  // import { throwError } from '../../throwError.js'
23
20
  // import { AnyComponentType } from '../../AnyComponentType.js'
@@ -27,11 +24,8 @@
27
24
  // import { globalDataFunc } from '../../routing/registerGlobalData.js'
28
25
  // import { ServerDataLoading } from '../../Store/ServerDataLoading.js'
29
26
  // import { ServerMiddleware } from '../ServerMiddleware.js'
30
- // import { TungstenServer } from '../TungstenServer.jsx'
31
27
  // import { portError } from '../portError.js'
32
28
  // import { initStores } from '../initStores.js'
33
- // import { RoutingRedirect } from '../../routing/RoutingRedirect.js'
34
- // import { RedirectComponent } from 'tungsten/components/RedirectComponent.js'
35
29
  // import { TungstenServerHono } from './TungstenServerHono.jsx'
36
30
  export {};
37
31
  // function debug(...texts: any[]) { // eslint-disable-line @typescript-eslint/no-unused-vars
@@ -43,15 +37,11 @@ export {};
43
37
  // compilationInfo: CompilationInfo
44
38
  // appRoutes: AppRoutes
45
39
  // RootComponentOrNull: AnyComponentType | null
46
- // // projectDir: string
47
- // // prodBuildLocation: string
48
- // // bundleLocation: string
49
- // //port: number
50
40
  // location: string | null = null
51
- // app: express.Application
41
+ // app: Hono
52
42
  // apiRoutesPromise?: Promise<ApiRoutes>
53
43
  // apiRoutes?: ApiRoutes
54
- // server?: Server
44
+ // server?: ServerType
55
45
  // constructor(
56
46
  // framework: Framework,
57
47
  // config: FrameworkConfigComplete,
@@ -66,40 +56,29 @@ export {};
66
56
  // this.compilationInfo = compilationInfo
67
57
  // this.appRoutes = appRoutes
68
58
  // this.RootComponentOrNull = RootComponentOrNull
69
- // // if (tungstenPrivateEnv.TUNGSTEN_SERVER_PORT === -999) {
70
- // // throwError('ProdServer', 'TUNGSTEN_SERVER_PORT environment variable has not been set')
71
- // // }
72
- // // !! I wrote this line while drunk. Please check this over. I think its wrong
73
- // //const _port = Number((typeof tungstenPrivateEnv !== 'undefined')
74
- // // ? tungstenPrivateEnv.TUNGSTEN_SERVER_PORT
75
- // // : process.env.TUNGSTEN_SERVER_PORT)
76
- // // seems like all we need is:
77
- // this.app = express()
59
+ // this.app = new Hono()
78
60
  // if (tungstenPrivateEnv.DEBUG === true) {
79
61
  // let reqId = 0
80
- // this.app.use((req, res, next) => {
62
+ // this.app.use(async (c, next) => {
81
63
  // reqId++
82
- // cliDebug(`Received request [${reqId}] for ${req.url}`)
83
- // next()
64
+ // cliDebug(`Received request [${reqId}] for ${c.req.url}`)
65
+ // await next()
84
66
  // })
85
67
  // }
86
68
  // const requestLog = (tungstenPrivateEnv.DEBUG === true)
87
69
  // const originMismatchWarning = (this.config.suppressOriginMismatchWarning !== true)
88
70
  // if (requestLog || originMismatchWarning) {
89
- // this.app.use((req, res, next) => {
90
- // const target = req.protocol + '://' + String(req.header('host')) + req.url
91
- // const origin = req.header('origin')
92
- // // request log
71
+ // this.app.use(async (c, next) => {
72
+ // const urlObj = new URL(c.req.url)
73
+ // const target = urlObj.origin + c.req.url
74
+ // const origin = c.req.header('origin')
93
75
  // if (requestLog) {
94
76
  // let message = 'Received request at ' + target
95
77
  // if (origin !== undefined) {
96
- // message += ' from ' + String(req.header('origin'))
97
- // // should we use referrer as a backup option?
98
- // // not sure what that is
78
+ // message += ' from ' + String(c.req.header('origin'))
99
79
  // }
100
80
  // cliOut(message)
101
81
  // }
102
- // // origin-target mismatch warning
103
82
  // if (originMismatchWarning) {
104
83
  // if (origin !== undefined && origin === this.location && origin !== target) {
105
84
  // cliWarn(
@@ -110,131 +89,70 @@ export {};
110
89
  // )
111
90
  // }
112
91
  // }
113
- // next()
92
+ // await next()
114
93
  // })
115
94
  // }
95
+ // // serverMiddleware isn't ported to Hono yet - it's a list of Express RequestHandlers,
96
+ // // which Hono's middleware signature can't run directly.
116
97
  // if (serverMiddleware) {
117
- // const { path, middlewares } = serverMiddleware
118
- // this.app.use(path, middlewares)
98
+ // cliWarn('ProdServerHono: serverMiddleware is not yet supported on the Hono server')
119
99
  // }
120
- // //this.app.set('etag', false)
121
100
  // if (this.compilationInfo.bundleLocation === undefined) {
122
- // throwError('ProdServer', 'compilationInfo.bundleLocation is unset/undefined')
101
+ // throwError('ProdServerHono', 'compilationInfo.bundleLocation is unset/undefined')
123
102
  // }
124
- // this.app.use('/bundle', express.static(this.compilationInfo.bundleLocation))
103
+ // this.app.use('/bundle/*', serveStatic({ root: this.compilationInfo.bundleLocation }))
125
104
  // const publicLocation = join(this.compilationInfo.location, publicFolder)
126
- // //console.log('publicLocation', publicLocation, existsSync(publicLocation))
127
- // if (existsSync(publicLocation)) this.app.use(express.static(publicLocation)) // files from public folder
128
- // //console.log("serving static files with etag")
129
- // this.app.use(express.static(join(this.compilationInfo.location, staticFolder)))
105
+ // if (existsSync(publicLocation)) this.app.use(serveStatic({ root: publicLocation })) // files from public folder
106
+ // this.app.use(serveStatic({ root: join(this.compilationInfo.location, staticFolder) }))
130
107
  // if (this.config.assetsDir !== undefined) {
131
- // this.app.use('/assets', express.static(join(this.compilationInfo.location, assetsFolder)))
108
+ // this.app.use('/assets/*', serveStatic({ root: join(this.compilationInfo.location, assetsFolder) }))
132
109
  // }
133
- // this.app.use(express.static(this.compilationInfo.location))
110
+ // this.app.use(serveStatic({ root: this.compilationInfo.location }))
134
111
  // if (typeof config.apiRoutes === 'string' && config.apiRoutes !== '') {
135
112
  // const apiPath = standardizeWebPath(this.config.apiPath)
136
113
  // cliOut(`API listening at ${apiPath}`)
137
- // this.app.use(apiPath, express.json())
138
114
  // this.app.use(apiPath, this.handleRequestApi)
139
115
  // }
140
116
  // this.app.use(this.handleRequest)
141
117
  // }
142
- // // private addServerMiddleware = (serverMiddleware: ServerMiddlewareInfo): void => {
143
- // // const [middlewareFile, middlewareExportName, middlewarePath] = serverMiddleware
144
- // // const fullFilePath = 'file://' + join(this.compilationInfo.codeLocation, middlewareFile)
145
- // // const middlewareModule = await import(fullFilePath)
146
- // // if ( ! (middlewareExportName in middlewareModule) ) {
147
- // // throwError('DevServer', `export ${middlewareExportName} not found in ${middlewareFile} when trying to load server middleware`)
148
- // // }
149
- // // const middleware = middlewareModule[middlewareExportName] as RequestHandler[]
150
- // // console.log('prod middleware', middleware)
151
- // // const path = middlewarePath.startsWith('/') ? middlewarePath : '/' + middlewarePath
152
- // // console.log('path', `|${path}|`)
153
- // // console.log('this.app', this.app)
154
- // // this.app.use('/api', (req, res, next) => {
155
- // // console.log('request to api 1')
156
- // // next()
157
- // // })
158
- // // this.app.use(path, (req, res, next) => {
159
- // // console.log('request to api')
160
- // // next()
161
- // // })
162
- // // this.app.use(path, middleware)
163
- // // cliOut(`Server Middleware added to server at ${path}`)
164
- // // }
165
- // private handleRequestApi = async (
166
- // req: express.Request, res: express.Response, next: express.NextFunction
167
- // ): Promise<void> => {
118
+ // private handleRequestApi = async (c: Context): Promise<Response> => { // eslint-disable-line @typescript-eslint/no-unused-vars
168
119
  // //this.apiRoutes = await this.apiRoutesPromise
169
120
  // throw new TungstenError(`handleRequestApi incomplete in dev server - add to get the API in the build step`)
170
- // // const requestPath = standardizeWebPath(req.baseUrl + req.path)
171
- // // for (const [path, route] of Object.entries(this.apiRoutes)) {
172
- // // //console.log(path, 'vs', requestPath)
173
- // // //console.log('path', path, standardizeWebPath(path))
174
- // // if (standardizeWebPath(path) === requestPath) {
175
- // // //console.log('API route matched', path)
176
- // // return route.endpoint(req, res)
177
- // // }
178
- // // }
179
- // // // else
180
- // // res.sendStatus(404)
181
121
  // }
182
- // handleRequest = async (req: express.Request, res: express.Response): Promise<void> => {
183
- // if (/\.(css|scss|sass|js|jsx|png|jpg|jpeg|svg|ico|txt)$/.test(req.url)) {
122
+ // handleRequest = async (c: Context): Promise<Response> => {
123
+ // const { req } = c
124
+ // if (/\.(css|scss|sass|js|jsx|png|jpg|jpeg|svg|ico|txt)$/.test(req.path)) {
184
125
  // cliLog(`Requested asset file ${req.url} was not found`)
185
- // res.status(404).end()
186
- // return
126
+ // return c.notFound()
187
127
  // }
188
128
  // try {
189
129
  // const location = req.url
190
130
  // const instanceConfig = makeInstanceConfigFromFrameworkConfig(this.config)
191
131
  // if (this.framework.frameworkModules === undefined) {
192
- // throwError('ProdServer.handleRequest()',
132
+ // throwError('ProdServerHono.handleRequest()',
193
133
  // 'framework.frameworkModules is undefined'
194
134
  // )
195
135
  // }
196
136
  // if (this.framework.clientImportAliases === undefined) {
197
- // throwError('ProdServer.handleRequest()',
137
+ // throwError('ProdServerHono.handleRequest()',
198
138
  // 'framework.clientImportAliases is undefined'
199
139
  // )
200
140
  // }
201
- // // const appRoutes: AppRoutes = await getRoutes(this.compilationInfo, this.config)
202
- // // let RootComponentClass: AnyComponentType
203
- // // if (this.config.useRootComponent) {
204
- // // const rootComponentFileFull = join(this.compilationInfo.location, this.config.rootComponent)
205
- // // RootComponentClass = await getComponent(rootComponentFileFull, this.config.rootComponent)
206
- // // } else {
207
- // // throwError('DevServer', 'useRootComponent = false not implemented yet')
208
- // // }
209
141
  // const { compilationInfo, config, appRoutes, RootComponentOrNull } = this
210
- // const reqRes: ReqRes = { req, res }
211
- // //const routes = instance.getRoutes()
142
+ // // ReqRes is Express-shaped ({req, res}) and Hono's Context isn't - this cast is a
143
+ // // type-only bridge so the (Express-only) Instance/initStores/routing plumbing below
144
+ // // still compiles. Not behaviorally correct; fine since this prod server isn't wired
145
+ // // up anywhere live.
146
+ // // eslint-disable-next-line no-type-assertion/no-type-assertion -- see comment above
147
+ // const reqRes = c as unknown as ReqRes
212
148
  // const serverDataLoading: ServerDataLoading = { value: false }
213
149
  // const routes = (typeof appRoutes === 'function') ? appRoutes(reqRes) : appRoutes
214
150
  // const [globalData, matchedRouteInfo] = await Promise.all([
215
151
  // (globalDataFunc.value !== undefined) ? globalDataFunc.value(reqRes) : {},
216
152
  // routing(location, routes, serverDataLoading)
217
153
  // ])
218
- // //instance.matchedRouteInfo =
219
- // //cliTodo('Can we move redirect handling to base class?')
220
- // // // 2025-03-14 copied this code here from Dev server,
221
- // // // because it looked like it was missing
222
- // // if (matchedRouteInfo.data instanceof RoutingRedirect) {
223
- // // const redirect = matchedRouteInfo.data
224
- // // res.redirect(redirect.code, redirect.to)
225
- // // return
226
- // // }
227
- // // // handle redirect components
228
- // // if (
229
- // // matchedRouteInfo.content instanceof RedirectComponent
230
- // // //&& matchedRouteInfo.content.__tungstenComponentType === 'redirect'
231
- // // ) {
232
- // // const { code = 302, to } = matchedRouteInfo.content.props
233
- // // res.redirect(code, to)
234
- // // return
235
- // // }
236
- // const redirected = this.handleRedirects(res, matchedRouteInfo)
237
- // if (redirected) return // end early
154
+ // const redirected = this.handleRedirects(c, matchedRouteInfo)
155
+ // if (redirected !== false) return redirected // end early
238
156
  // const { internalStore, stores, storeSubscriptions }
239
157
  // = initStores(location, reqRes, globalData, matchedRouteInfo, serverDataLoading)
240
158
  // const instance = new Instance(
@@ -252,22 +170,16 @@ export {};
252
170
  // let { content } = matchedRouteInfo
253
171
  // if (typeof content === 'function') {
254
172
  // content = content(data, params, {} /* props */, globalData, location)
255
- // //throwError('DevServer', 'route content is a function')
256
173
  // }
257
174
  // html = await renderContentToHtml(
258
175
  // this.compilationInfo, this.framework.clientImportAliases,
259
176
  // content, instance, config, this.config.siteBasePath
260
177
  // )
261
178
  // }
262
- // //debug('html', html)
263
- // res.setHeader('Content-Type', 'text/html')
264
- // res.status((instance.matchedRouteInfo.key === '404') ? 404 : 200)
265
- // res.send(html)
179
+ // return c.html(html, (instance.matchedRouteInfo.key === '404') ? 404 : 200)
266
180
  // } catch(e) {
267
181
  // cliLog('handleRequest() error', e)
268
- // res.setHeader('Content-Type', 'text/html')
269
- // res.status(500)
270
- // res.send(this.errorPage())
182
+ // return c.html(this.errorPage(), 500)
271
183
  // }
272
184
  // }
273
185
  // errorPage = () => {
@@ -280,27 +192,23 @@ export {};
280
192
  // </body>
281
193
  // </html>`
282
194
  // }
283
- // // private async handlePost(req: express.Request, res: express.Response): Promise<void> {
284
- // // throw new TungstenError(`Err - Dev server received a post request. Not supported yet.`)
285
- // // }
286
195
  // // I don't think we ever override the port, not sure why
287
196
  // start(portOverride?: number | null, mute = false): Promise<string> {
288
197
  // return new Promise( (resolve) => {
289
- // const proto = tungstenPrivateEnv.FRONTEND_PROTO ?? 'http'
290
- // const host = tungstenPrivateEnv.FRONTEND_HOST ?? 'localhost'
198
+ // const proto = tungstenPublicEnv.FRONTEND_PROTO ?? 'http'
199
+ // const host = tungstenPublicEnv.FRONTEND_HOST ?? 'localhost'
291
200
  // let port: number | null
292
201
  // if (portOverride !== undefined) {
293
202
  // port = portOverride
294
203
  // } else {
295
204
  // const _port = tungstenPrivateEnv.TUNGSTEN_SERVER_PORT ?? 3000
296
- // if (isNaN(_port) || _port === 0) throwError('ProdServer', portError(_port))
205
+ // if (isNaN(_port) || _port === 0) throwError('ProdServerHono', portError(_port))
297
206
  // port = _port
298
207
  // }
299
- // //const port = (portOverride !== undefined) ? portOverride : port
300
- // // eslint-disable-next-line no-console
301
- // this.server = this.app.listen(port, () => {
302
- // const serverAddress = this.server!.address() as AddressInfo // eslint-disable-line @typescript-eslint/no-non-null-assertion, no-type-assertion/no-type-assertion
303
- // this.location = `${proto}://${host}:${serverAddress.port}`
208
+ // if (port === null) throwError('ProdServerHono', portError(NaN))
209
+ // if (isNaN(port) || port === 0) throwError('ProdServerHono', portError(port))
210
+ // this.server = serve({ fetch: this.app.fetch, port }, info => {
211
+ // this.location = `${proto}://${host}:${info.port}`
304
212
  // if (!mute) cliNews(`${packageNameCapitalized} prod server ready at ${this.location}`)
305
213
  // resolve(this.location)
306
214
  // })
@@ -309,5 +217,4 @@ export {};
309
217
  // stop() {
310
218
  // if (this.server !== undefined) this.server.close()
311
219
  // }
312
- // //treeToHtml = treeToHtml
313
220
  // }
@@ -1,6 +1,6 @@
1
1
  import type { MatchedRouteInfo } from '../MatchedRouteInfo.js';
2
2
  import { Context } from 'hono';
3
3
  export declare class TungstenServerHono {
4
- protected handleRedirects(c: Context, matchedRouteInfo: MatchedRouteInfo): boolean;
4
+ protected handleRedirects(c: Context, matchedRouteInfo: MatchedRouteInfo): Response | false;
5
5
  }
6
6
  //# sourceMappingURL=TungstenServerHono.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TungstenServerHono.d.ts","sourceRoot":"","sources":["../../../src/Servers/hono/TungstenServerHono.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG9D,OAAO,EAAQ,OAAO,EAAE,MAAM,MAAM,CAAA;AAuBpC,qBAAa,kBAAkB;IAC3B,SAAS,CAAC,eAAe,CAAC,CAAC,EAAE,OAAO,EAAY,gBAAgB,EAAE,gBAAgB,GAAG,OAAO;CA6C/F"}
1
+ {"version":3,"file":"TungstenServerHono.d.ts","sourceRoot":"","sources":["../../../src/Servers/hono/TungstenServerHono.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAU9B,qBAAa,kBAAkB;IAI3B,SAAS,CAAC,eAAe,CAAC,CAAC,EAAE,OAAO,EAAY,gBAAgB,EAAE,gBAAgB,GAAG,QAAQ,GAAG,KAAK;CAoCxG"}