@txco/nitro-preset 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ // The server entry: Nitro's app as a Fetch handler, in the Web ABI's server
2
+ // shape, `export default { fetch(request, ctx) }` with ctx = { client: { ip } }.
3
+ // Nitro bundles this file into server/index.mjs; the imports below are its
4
+ // own, resolved at bundle time.
5
+ import "#nitro-internal-pollyfills";
6
+ import { useNitroApp } from "nitropack/runtime";
7
+
8
+ interface Context {
9
+ client?: { ip?: string };
10
+ }
11
+
12
+ const nitroApp = useNitroApp();
13
+
14
+ export default {
15
+ async fetch(request: Request, ctx?: Context): Promise<Response> {
16
+ const url = new URL(request.url);
17
+ const method = request.method.toUpperCase();
18
+ const body = method === "GET" || method === "HEAD" ? undefined : Buffer.from(await request.arrayBuffer());
19
+ return nitroApp.localFetch(url.pathname + url.search, {
20
+ host: url.hostname,
21
+ protocol: url.protocol,
22
+ method,
23
+ headers: request.headers,
24
+ body,
25
+ // Nitro spreads _platform into event.context; h3's getRequestIP reads
26
+ // context.clientAddress first.
27
+ context: {
28
+ _platform: { clientAddress: ctx?.client?.ip, thanksComputer: { client: ctx?.client } },
29
+ },
30
+ } as Parameters<typeof nitroApp.localFetch>[1]);
31
+ },
32
+ };
@@ -0,0 +1,2 @@
1
+ // Nitro's virtual modules, resolved when Nitro bundles the server entry.
2
+ declare module "#nitro-internal-pollyfills";
package/src/types.ts ADDED
@@ -0,0 +1,23 @@
1
+ /** Options, set as `nitro: { thanksComputer: { … } }` (Nuxt) or the Nitro config's `thanksComputer`. */
2
+ export interface ThanksComputerOptions {
3
+ /**
4
+ * Answer every unknown page path with the app shell and 200, for an app
5
+ * that routes in the browser. Detected for Nuxt `ssr: false` and Analog's
6
+ * client renderer; set it to force the choice either way.
7
+ */
8
+ spa?: boolean;
9
+ /**
10
+ * The public/ prefixes cached for a year (`["assets/"]`), each a directory
11
+ * ending in "/". Derived from the framework's asset dirs when unset (Nuxt:
12
+ * `_nuxt/`).
13
+ */
14
+ immutable?: string[];
15
+ /** The scope of the navigation op; the catch-all goes 900 above it. Default 900000. */
16
+ scope?: number;
17
+ }
18
+
19
+ declare module "nitropack/presets" {
20
+ interface PresetOptions {
21
+ thanksComputer?: ThanksComputerOptions;
22
+ }
23
+ }