@arkstack/driver-h3 0.14.22 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as staticAssetHandler } from "./middlewares-
|
|
1
|
+
import { t as staticAssetHandler } from "./middlewares-BORI5o6J.js";
|
|
2
2
|
import { ArkstackKitDriver } from "@arkstack/contract";
|
|
3
3
|
import { H3, HTTPResponse, serve, toResponse } from "h3";
|
|
4
|
-
import { ErrorHandler, Logger, env, renderError, resolveRuntimeModule } from "@arkstack/common";
|
|
4
|
+
import { ErrorHandler, Logger, devTlsCredentials, env, localNetworkAddress, renderError, resolveRuntimeModule } from "@arkstack/common";
|
|
5
5
|
import ngrok from "@ngrok/ngrok";
|
|
6
6
|
import { resolveMiddleware } from "@arkstack/http";
|
|
7
7
|
import { registerPlugin } from "resora";
|
|
@@ -181,13 +181,23 @@ var H3Driver = class extends ArkstackKitDriver {
|
|
|
181
181
|
*/
|
|
182
182
|
async start(app, port) {
|
|
183
183
|
const host = env("APP_HOST", env("HOST", "0.0.0.0"));
|
|
184
|
+
const secure = env("APP_SECURE", false) === true;
|
|
184
185
|
const tunneled = env("TUNNEL", false);
|
|
185
|
-
const
|
|
186
|
+
const scheme = secure ? "https" : "http";
|
|
187
|
+
const tls = secure ? await devTlsCredentials() : void 0;
|
|
188
|
+
await serve(app, {
|
|
186
189
|
port,
|
|
187
190
|
hostname: host,
|
|
188
|
-
silent: true
|
|
191
|
+
silent: true,
|
|
192
|
+
...tls ? {
|
|
193
|
+
protocol: "https",
|
|
194
|
+
tls: {
|
|
195
|
+
cert: tls.cert,
|
|
196
|
+
key: tls.key
|
|
197
|
+
}
|
|
198
|
+
} : {}
|
|
189
199
|
}).ready();
|
|
190
|
-
let log =
|
|
200
|
+
let log = startupLogLines(scheme, host, port);
|
|
191
201
|
if (tunneled === true) {
|
|
192
202
|
const url = (await ngrok.forward({
|
|
193
203
|
addr: port,
|
|
@@ -204,5 +214,20 @@ var H3Driver = class extends ArkstackKitDriver {
|
|
|
204
214
|
console.log(log.join("\n"));
|
|
205
215
|
}
|
|
206
216
|
};
|
|
217
|
+
/**
|
|
218
|
+
* Build the "Server is running" startup lines, adding a local-network URL when
|
|
219
|
+
* the server is bound to all interfaces (`0.0.0.0`/`::`) so it is reachable from
|
|
220
|
+
* other devices.
|
|
221
|
+
*/
|
|
222
|
+
const startupLogLines = (scheme, host, port) => {
|
|
223
|
+
const bindsAll = host === "0.0.0.0" || host === "::";
|
|
224
|
+
const localHost = bindsAll ? "localhost" : host;
|
|
225
|
+
const lines = [Logger.log([["Server is running on", "white"], [`${scheme}://${localHost}:${port}`, "cyan"]], " ", false)];
|
|
226
|
+
if (bindsAll) {
|
|
227
|
+
const address = localNetworkAddress();
|
|
228
|
+
if (address) lines.push(Logger.log([["Network access via", "white"], [`${scheme}://${address}:${port}`, "cyan"]], " ", false));
|
|
229
|
+
}
|
|
230
|
+
return lines;
|
|
231
|
+
};
|
|
207
232
|
//#endregion
|
|
208
233
|
export { H3Driver, H3EventResponse, Router, defaultErrorHandler };
|
|
@@ -35,6 +35,26 @@ declare class CorsMiddleware {
|
|
|
35
35
|
handler(event: H3Event<EventHandlerRequest>, next: NextFunction): Promise<void>;
|
|
36
36
|
}
|
|
37
37
|
//#endregion
|
|
38
|
+
//#region src/middlewares/inertia.d.ts
|
|
39
|
+
/**
|
|
40
|
+
* Bind the Inertia request context for H3.
|
|
41
|
+
*
|
|
42
|
+
* Normalizes the H3 event into the adapter's driver-agnostic shape and runs the
|
|
43
|
+
* downstream handler inside Inertia's async-local context (mirroring the `resora`
|
|
44
|
+
* middleware), so `inertia()` / `Inertia.*` resolve the active request.
|
|
45
|
+
*
|
|
46
|
+
* It also upgrades a `302` redirect returned for a `PUT`/`PATCH`/`DELETE` Inertia
|
|
47
|
+
* visit to `303 See Other`, which the Inertia client requires to follow the
|
|
48
|
+
* redirect with a `GET`. (Prefer `Inertia.redirect()` / `Inertia.back()`, which
|
|
49
|
+
* already emit the correct status.)
|
|
50
|
+
*
|
|
51
|
+
* `@arkstack/inertia` is imported dynamically so the package stays optional.
|
|
52
|
+
*/
|
|
53
|
+
declare const inertia: () => (event: H3Event, next: NextFunction) => Promise<unknown>;
|
|
54
|
+
declare class InertiaMiddleware {
|
|
55
|
+
handler(event: H3Event, next: NextFunction): Promise<unknown>;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
38
58
|
//#region src/middlewares/request-logger.d.ts
|
|
39
59
|
/**
|
|
40
60
|
* Middleware to log incoming requests and their response times.
|
|
@@ -71,4 +91,4 @@ declare const resora: () => (event: H3Event, next: NextFunction) => Promise<unkn
|
|
|
71
91
|
//#region src/middlewares/static-asset-handler.d.ts
|
|
72
92
|
declare const staticAssetHandler: (publicPath?: string) => (event: H3Event) => Promise<_$h3.HTTPResponse | undefined> | undefined;
|
|
73
93
|
//#endregion
|
|
74
|
-
export { AuthMiddleware, CorsMiddleware, RequestLoggerMiddleware, auth, cors, requestLogger, resora, staticAssetHandler };
|
|
94
|
+
export { AuthMiddleware, CorsMiddleware, InertiaMiddleware, RequestLoggerMiddleware, auth, cors, inertia, requestLogger, resora, staticAssetHandler };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { AuthMiddleware, CorsMiddleware, RequestLoggerMiddleware, auth, cors, requestLogger, resora, staticAssetHandler };
|
|
1
|
+
import { a as InertiaMiddleware, c as cors, i as requestLogger, l as AuthMiddleware, n as resora, o as inertia, r as RequestLoggerMiddleware, s as CorsMiddleware, t as staticAssetHandler, u as auth } from "../middlewares-BORI5o6J.js";
|
|
2
|
+
export { AuthMiddleware, CorsMiddleware, InertiaMiddleware, RequestLoggerMiddleware, auth, cors, inertia, requestLogger, resora, staticAssetHandler };
|
|
@@ -273,6 +273,43 @@ var CorsMiddleware = class {
|
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
275
|
//#endregion
|
|
276
|
+
//#region src/middlewares/inertia.ts
|
|
277
|
+
/**
|
|
278
|
+
* Bind the Inertia request context for H3.
|
|
279
|
+
*
|
|
280
|
+
* Normalizes the H3 event into the adapter's driver-agnostic shape and runs the
|
|
281
|
+
* downstream handler inside Inertia's async-local context (mirroring the `resora`
|
|
282
|
+
* middleware), so `inertia()` / `Inertia.*` resolve the active request.
|
|
283
|
+
*
|
|
284
|
+
* It also upgrades a `302` redirect returned for a `PUT`/`PATCH`/`DELETE` Inertia
|
|
285
|
+
* visit to `303 See Other`, which the Inertia client requires to follow the
|
|
286
|
+
* redirect with a `GET`. (Prefer `Inertia.redirect()` / `Inertia.back()`, which
|
|
287
|
+
* already emit the correct status.)
|
|
288
|
+
*
|
|
289
|
+
* `@arkstack/inertia` is imported dynamically so the package stays optional.
|
|
290
|
+
*/
|
|
291
|
+
const inertia = () => {
|
|
292
|
+
return async (event, next) => {
|
|
293
|
+
const { runInertia, shouldUpgradeRedirect } = await import("@arkstack/inertia");
|
|
294
|
+
const sourceUrl = event.req._url ? event.req._url.pathname + event.req._url.search : event.req.url || "/";
|
|
295
|
+
const request = {
|
|
296
|
+
method: String(event.req.method ?? "GET").toUpperCase(),
|
|
297
|
+
url: sourceUrl,
|
|
298
|
+
header: (name) => event.req.headers.get(name) ?? void 0
|
|
299
|
+
};
|
|
300
|
+
return runInertia(request, async () => {
|
|
301
|
+
const result = await next();
|
|
302
|
+
if (request.header("x-inertia") === "true" && result && typeof result === "object" && typeof result.statusCode === "number" && shouldUpgradeRedirect(request.method, result.statusCode)) result.statusCode = 303;
|
|
303
|
+
return result;
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
var InertiaMiddleware = class {
|
|
308
|
+
handler(event, next) {
|
|
309
|
+
return inertia()(event, next);
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
//#endregion
|
|
276
313
|
//#region src/middlewares/request-logger.ts
|
|
277
314
|
const colors = {
|
|
278
315
|
GET: "green",
|
|
@@ -372,4 +409,4 @@ const staticAssetHandler = (publicPath = "public") => {
|
|
|
372
409
|
};
|
|
373
410
|
};
|
|
374
411
|
//#endregion
|
|
375
|
-
export {
|
|
412
|
+
export { InertiaMiddleware as a, cors as c, requestLogger as i, AuthMiddleware as l, resora as n, inertia as o, RequestLoggerMiddleware as r, CorsMiddleware as s, staticAssetHandler as t, auth as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkstack/driver-h3",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "H3 driver for Arkstack, providing H3-based runtime integration for the framework.",
|
|
6
6
|
"homepage": "https://arkstack.toneflix.net",
|
|
@@ -41,17 +41,21 @@
|
|
|
41
41
|
"@resora/plugin-clear-router": "^1.0.66",
|
|
42
42
|
"clear-router": "^2.9.0",
|
|
43
43
|
"resora": "^1.3.27",
|
|
44
|
-
"@arkstack/contract": "^0.
|
|
44
|
+
"@arkstack/contract": "^0.15.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"h3": "2.0.1-rc.22",
|
|
48
|
-
"@arkstack/auth": "^0.
|
|
49
|
-
"@arkstack/common": "^0.
|
|
50
|
-
"@arkstack/foundry": "^0.
|
|
48
|
+
"@arkstack/auth": "^0.15.1",
|
|
49
|
+
"@arkstack/common": "^0.15.1",
|
|
50
|
+
"@arkstack/foundry": "^0.15.1",
|
|
51
|
+
"@arkstack/inertia": "^0.15.1"
|
|
51
52
|
},
|
|
52
53
|
"peerDependenciesMeta": {
|
|
53
54
|
"@arkstack/auth": {
|
|
54
55
|
"optional": true
|
|
56
|
+
},
|
|
57
|
+
"@arkstack/inertia": {
|
|
58
|
+
"optional": true
|
|
55
59
|
}
|
|
56
60
|
},
|
|
57
61
|
"scripts": {
|