noofpi 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +47 -2
- package/bin/noofpi.mjs +2 -0
- package/client.d.ts +79 -0
- package/dist/build-77DKK3YK.js +48 -0
- package/dist/chunk-2XCZWFIQ.js +253 -0
- package/dist/chunk-6OWKWAIW.js +68 -0
- package/dist/chunk-ELXCFUA4.js +97 -0
- package/dist/chunk-EZPJF4D4.js +314 -0
- package/dist/chunk-FIJJ3EGL.js +353 -0
- package/dist/chunk-G35DW4NA.js +129 -0
- package/dist/chunk-KAV3UNMO.js +996 -0
- package/dist/chunk-KGZP2RCF.js +51 -0
- package/dist/chunk-MTWSTW7V.js +44 -0
- package/dist/chunk-MTXQR32N.js +8 -0
- package/dist/chunk-NALDZ3PS.js +90 -0
- package/dist/chunk-WX2V6EYH.js +102 -0
- package/dist/chunk-WXEYXDO6.js +280 -0
- package/dist/chunk-X34Y6ESE.js +810 -0
- package/dist/chunk-Y3NBZ6DW.js +55 -0
- package/dist/chunk-YZAZ7IWK.js +27 -0
- package/dist/cli.js +93 -0
- package/dist/dev-ZJ732ORK.js +122 -0
- package/dist/devtools-KTDSD5PR.js +564 -0
- package/dist/images-BNwTAi50.d.ts +36 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +15 -0
- package/dist/route-rules-COilNsVT.d.ts +127 -0
- package/dist/runtime/default-app.js +15 -0
- package/dist/runtime/entry-client.js +70 -0
- package/dist/runtime/entry-server.js +107 -0
- package/dist/runtime/index.d.ts +523 -0
- package/dist/runtime/index.js +224 -0
- package/dist/runtime/routes.js +14 -0
- package/dist/server/bun.js +47 -0
- package/dist/server/index.d.ts +109 -0
- package/dist/server/index.js +48 -0
- package/dist/server/node.js +15 -0
- package/dist/start-I2LQWV7B.js +61 -0
- package/dist/validation-ClXd_DAW.d.ts +159 -0
- package/package.json +101 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { UserConfig } from 'vite';
|
|
2
|
+
import { R as RouteRules, H as HeadConfig, S as SecurityConfig, F as FetchMode } from './route-rules-COilNsVT.js';
|
|
3
|
+
export { C as CspConfig, a as CspDirectiveName, b as CspDirectiveValue, c as CsrfConfig, d as FETCH_MODES, e as HeadInput, f as HeadTag, g as RouteRule } from './route-rules-COilNsVT.js';
|
|
4
|
+
import { I as ImagesConfig, a as I18nConfig } from './images-BNwTAi50.js';
|
|
5
|
+
export { b as ImageFormat } from './images-BNwTAi50.js';
|
|
6
|
+
|
|
7
|
+
declare const BUILD_PRESETS: readonly ["node", "bun", "docker", "cloudflare-worker", "cloudflare-pages", "github-pages"];
|
|
8
|
+
/**
|
|
9
|
+
* - `node`: `.output/` runs with `noofpi start` or `node .output/server/start.mjs`
|
|
10
|
+
* - `bun`: like `node`, served with `Bun.serve` (`bun .output/server/start.mjs`)
|
|
11
|
+
* - `docker`: like `node`, plus `.output/Dockerfile`
|
|
12
|
+
* - `cloudflare-worker`: one bundled Worker (`server/index.mjs`) with static assets, plus `wrangler.json`
|
|
13
|
+
* - `cloudflare-pages`: `public/` with a bundled `_worker.js`, deployable with `wrangler pages deploy`
|
|
14
|
+
* - `github-pages`: static client-only SPA in `public/` (no server): `index.html`, a `404.html` fallback and `.nojekyll`
|
|
15
|
+
*/
|
|
16
|
+
type BuildPreset = (typeof BUILD_PRESETS)[number];
|
|
17
|
+
|
|
18
|
+
/** Built-in font providers. To add one, extend this list and register it in `providers/index.ts` */
|
|
19
|
+
declare const FONT_PROVIDERS: readonly ["google", "local"];
|
|
20
|
+
type FontProviderName = (typeof FONT_PROVIDERS)[number];
|
|
21
|
+
/** `400`, `"bold"`, or a variable range like `"100 900"` */
|
|
22
|
+
type FontWeight = number | string;
|
|
23
|
+
type FontStyle = "normal" | "italic";
|
|
24
|
+
type FontDisplay = "auto" | "block" | "swap" | "fallback" | "optional";
|
|
25
|
+
interface FontFamilyBase {
|
|
26
|
+
/** CSS font-family name, e.g. `Inter` */
|
|
27
|
+
name: string;
|
|
28
|
+
/** `font-display` (default: `swap`) */
|
|
29
|
+
display?: FontDisplay;
|
|
30
|
+
/** Fallback fonts appended after `name`, e.g. `["ui-sans-serif", "sans-serif"]` */
|
|
31
|
+
fallback?: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Theme key: gives the Tailwind `font-<alias>` utility and the `--font-<alias>` CSS variable.
|
|
34
|
+
* Default: the kebab-cased `name` (`Open Sans` -> `font-open-sans`). Use `sans`, `serif` or `mono` to replace
|
|
35
|
+
* Tailwind's default stacks
|
|
36
|
+
*/
|
|
37
|
+
alias?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Downloaded at dev/build time and self-hosted (cached in `.noofpi/fonts`) */
|
|
40
|
+
interface GoogleFontFamily extends FontFamilyBase {
|
|
41
|
+
provider: "google";
|
|
42
|
+
/** Weights to load (default: `400`). A range like `"100 900"` loads the variable font */
|
|
43
|
+
weight?: FontWeight | FontWeight[];
|
|
44
|
+
/** Default: `normal` */
|
|
45
|
+
style?: FontStyle | FontStyle[];
|
|
46
|
+
/** Google subsets to include, e.g. `["latin", "hebrew"]` (default: all; browsers only download what the page uses) */
|
|
47
|
+
subsets?: string[];
|
|
48
|
+
}
|
|
49
|
+
interface LocalFontFile {
|
|
50
|
+
/** Path relative to the project root, e.g. `app/assets/fonts/Inter.woff2` */
|
|
51
|
+
src: string;
|
|
52
|
+
weight?: FontWeight;
|
|
53
|
+
style?: FontStyle;
|
|
54
|
+
}
|
|
55
|
+
/** Font files from your project (woff2, woff, ttf, otf) */
|
|
56
|
+
interface LocalFontFamily extends FontFamilyBase {
|
|
57
|
+
provider: "local";
|
|
58
|
+
/** One file, or one entry per weight/style */
|
|
59
|
+
src: string | LocalFontFile[];
|
|
60
|
+
/** Default weight of `src` entries (default: `400`) */
|
|
61
|
+
weight?: FontWeight;
|
|
62
|
+
/** Default style of `src` entries (default: `normal`) */
|
|
63
|
+
style?: FontStyle;
|
|
64
|
+
}
|
|
65
|
+
type FontFamily = GoogleFontFamily | LocalFontFamily;
|
|
66
|
+
interface FontsConfig {
|
|
67
|
+
families: FontFamily[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface NoofpiConfig {
|
|
71
|
+
/** Render pages on the server (`true`, default) or ship a client-only SPA (`false`) */
|
|
72
|
+
ssr?: boolean;
|
|
73
|
+
/** Per-route overrides keyed by URL pattern (`/admin/**`, `/users/*`, `/about`), e.g. `{ "/admin/**": { ssr: false, fetch: "pfetch" } }` */
|
|
74
|
+
routeRules?: RouteRules;
|
|
75
|
+
/** Default `<head>` of every page: `title` (put `%s` where a page's `useHead({ title })` goes), `meta`, `link`, `htmlAttrs`, `bodyAttrs` */
|
|
76
|
+
head?: HeadConfig;
|
|
77
|
+
/** Enable the built-in Tailwind CSS (v4) vite plugin */
|
|
78
|
+
tailwind?: boolean;
|
|
79
|
+
/** Nuxt-style auto-imports for Vue, vue-router, noofpi composables, `app/composables`, `app/utils` and `app/components` (default: `true`) */
|
|
80
|
+
autoImports?: boolean;
|
|
81
|
+
/** CSS files (relative to the project root). Defaults to `app/assets/main.css` when it exists */
|
|
82
|
+
css?: string[];
|
|
83
|
+
/** Built-in fonts: Google fonts (self-hosted) and local font files, usable from CSS and Tailwind */
|
|
84
|
+
fonts?: FontsConfig;
|
|
85
|
+
/** Image pipeline of `import img from "./img.jpg?image"` (used by `<NoofpiImage>`): AVIF / WebP variants at several widths */
|
|
86
|
+
images?: ImagesConfig;
|
|
87
|
+
/** Built-in security: `csp` (with automatic nonces), security response `headers`, `csrf` protection of the API, request `bodyLimit` and `allowedHosts` */
|
|
88
|
+
security?: SecurityConfig;
|
|
89
|
+
/** Built-in i18n: `t()` with typed message keys from `app/locales/<locale>.ts`, locale detection (cookie, `Accept-Language`) and `<html lang dir>`. Off unless set */
|
|
90
|
+
i18n?: I18nConfig;
|
|
91
|
+
doofpi?: {
|
|
92
|
+
/** How the doofpi client reaches the API. Default: `lfetch`. `routeRules[...].fetch` overrides it per route */
|
|
93
|
+
fetch?: FetchMode;
|
|
94
|
+
/** Remote doofpi API origin. Required when `dfetch`, `pfetch` or `sfetch` is used (here or in `routeRules`) */
|
|
95
|
+
url?: string;
|
|
96
|
+
/** doofpi root path of the API. Default: `/doofpi` */
|
|
97
|
+
root?: string;
|
|
98
|
+
};
|
|
99
|
+
devServer?: {
|
|
100
|
+
port?: number;
|
|
101
|
+
host?: string;
|
|
102
|
+
};
|
|
103
|
+
build?: {
|
|
104
|
+
/** Deploy target of `noofpi build`: `node` (default), `bun`, `docker`, `cloudflare-worker`, `cloudflare-pages` or `github-pages` (static SPA). `--preset` overrides it */
|
|
105
|
+
preset?: BuildPreset;
|
|
106
|
+
};
|
|
107
|
+
/** Mini devtools overlay in `noofpi dev` (current route, middleware chain, fetch mode, doofpi requests, CSP violations). Never included in production builds. Default: `true` */
|
|
108
|
+
devtools?: boolean;
|
|
109
|
+
/** Extra vite options, merged into the generated config */
|
|
110
|
+
vite?: UserConfig;
|
|
111
|
+
}
|
|
112
|
+
declare function defineNoofpiConfig(config: NoofpiConfig): NoofpiConfig;
|
|
113
|
+
|
|
114
|
+
export { BUILD_PRESETS, FONT_PROVIDERS, FetchMode, HeadConfig, I18nConfig, ImagesConfig, RouteRules, SecurityConfig, defineNoofpiConfig };
|
|
115
|
+
export type { BuildPreset, FontDisplay, FontFamily, FontProviderName, FontStyle, FontWeight, FontsConfig, GoogleFontFamily, LocalFontFamily, LocalFontFile, NoofpiConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILD_PRESETS,
|
|
3
|
+
FONT_PROVIDERS,
|
|
4
|
+
defineNoofpiConfig
|
|
5
|
+
} from "./chunk-WXEYXDO6.js";
|
|
6
|
+
import "./chunk-ELXCFUA4.js";
|
|
7
|
+
import {
|
|
8
|
+
FETCH_MODES
|
|
9
|
+
} from "./chunk-FIJJ3EGL.js";
|
|
10
|
+
export {
|
|
11
|
+
BUILD_PRESETS,
|
|
12
|
+
FETCH_MODES,
|
|
13
|
+
FONT_PROVIDERS,
|
|
14
|
+
defineNoofpiConfig
|
|
15
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
declare const FETCH_MODES: readonly ["dfetch", "pfetch", "lfetch", "sfetch"];
|
|
2
|
+
/**
|
|
3
|
+
* - `dfetch`: client -> doofpi API directly
|
|
4
|
+
* - `pfetch`: client -> noofpi server (proxy) -> doofpi API
|
|
5
|
+
* - `lfetch`: client -> noofpi's own doofpi API (`server/doofpi.ts`)
|
|
6
|
+
* - `sfetch`: server only, never from the browser
|
|
7
|
+
*/
|
|
8
|
+
type FetchMode = (typeof FETCH_MODES)[number];
|
|
9
|
+
|
|
10
|
+
type HeadAttrValue = string | number | boolean | null | undefined;
|
|
11
|
+
/** Attributes of a tag: `{ name: "description", content: "..." }`. `true` renders a bare attribute, `false`/`null`/`undefined` omit it */
|
|
12
|
+
type HeadTag = Record<string, HeadAttrValue>;
|
|
13
|
+
interface HeadInput {
|
|
14
|
+
/**
|
|
15
|
+
* In `useHead()`: the page title. In the config: the default title; put `%s` where the page title goes
|
|
16
|
+
* (`"%s | My site"`). Without `%s`, a page title replaces the default.
|
|
17
|
+
*/
|
|
18
|
+
title?: string;
|
|
19
|
+
meta?: HeadTag[];
|
|
20
|
+
link?: HeadTag[];
|
|
21
|
+
htmlAttrs?: Record<string, HeadAttrValue>;
|
|
22
|
+
bodyAttrs?: Record<string, HeadAttrValue>;
|
|
23
|
+
}
|
|
24
|
+
/** `head` option of `noofpi.config.ts`: defaults for every page */
|
|
25
|
+
type HeadConfig = HeadInput;
|
|
26
|
+
interface ResolvedHead {
|
|
27
|
+
title: string;
|
|
28
|
+
meta: Record<string, string>[];
|
|
29
|
+
link: Record<string, string>[];
|
|
30
|
+
htmlAttrs: Record<string, string>;
|
|
31
|
+
bodyAttrs: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A directive's sources: `["'self'", "https://cdn.example.com"]` or `"'self' https://cdn.example.com"`. `true` renders a bare directive (`upgrade-insecure-requests`), `false` omits it */
|
|
35
|
+
type CspDirectiveValue = string | string[] | boolean;
|
|
36
|
+
type CspDirectiveName = "default-src" | "script-src" | "script-src-elem" | "script-src-attr" | "style-src" | "style-src-elem" | "style-src-attr" | "img-src" | "font-src" | "connect-src" | "media-src" | "object-src" | "child-src" | "frame-src" | "worker-src" | "manifest-src" | "base-uri" | "form-action" | "frame-ancestors" | "sandbox" | "report-uri" | "report-to" | "upgrade-insecure-requests" | "require-trusted-types-for" | "trusted-types" | (string & {});
|
|
37
|
+
interface CspConfig {
|
|
38
|
+
/**
|
|
39
|
+
* Directives of the `Content-Security-Policy` header sent with every HTML page.
|
|
40
|
+
* Put `'nonce'` in a directive (typically `script-src` / `style-src`) to get a fresh nonce per request: it becomes
|
|
41
|
+
* `'nonce-<value>'` in the header and `nonce="<value>"` is added to every `<script>`, `<style>` and stylesheet /
|
|
42
|
+
* preload `<link>` of the page shell.
|
|
43
|
+
*/
|
|
44
|
+
directives: Partial<Record<CspDirectiveName, CspDirectiveValue>>;
|
|
45
|
+
/** Send `Content-Security-Policy-Report-Only` instead, so violations are reported but not blocked */
|
|
46
|
+
reportOnly?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface CsrfConfig {
|
|
50
|
+
/** Extra origins (`https://app.example.com`) allowed to send state-changing requests to the API. The site's own origin is always allowed */
|
|
51
|
+
allowedOrigins?: string[];
|
|
52
|
+
/** The site's public origin (`https://app.example.com`). When set, the `Origin` of a write must match it exactly, scheme included. Unset, only hosts are compared because a TLS-terminating proxy may hide https */
|
|
53
|
+
publicOrigin?: string;
|
|
54
|
+
}
|
|
55
|
+
interface SecurityConfig {
|
|
56
|
+
/** `Content-Security-Policy` of every HTML page. A `'nonce'` source gets a per-request nonce, added to the page's scripts and styles automatically */
|
|
57
|
+
csp?: CspConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Security response headers added to every response that does not already set them. `false` turns them all off;
|
|
60
|
+
* an object overrides single headers (`{ "X-Frame-Options": "DENY" }`) or removes one (`{ "Referrer-Policy": false }`).
|
|
61
|
+
* Defaults: `X-Content-Type-Options: nosniff`, `X-Frame-Options: SAMEORIGIN` (skipped when the CSP has
|
|
62
|
+
* `frame-ancestors`), `Referrer-Policy: strict-origin-when-cross-origin`, `Permissions-Policy` (camera, microphone and
|
|
63
|
+
* geolocation off) and, over https only, `Strict-Transport-Security`.
|
|
64
|
+
*/
|
|
65
|
+
headers?: boolean | Record<string, string | false>;
|
|
66
|
+
/**
|
|
67
|
+
* Blocks cross-site state-changing requests (POST, PUT, PATCH, DELETE) to the doofpi API and the pfetch proxy by
|
|
68
|
+
* checking `Origin` / `Sec-Fetch-Site`. On by default; `false` turns it off.
|
|
69
|
+
*/
|
|
70
|
+
csrf?: boolean | CsrfConfig;
|
|
71
|
+
/**
|
|
72
|
+
* Largest request body in bytes the server accepts (for the doofpi API, the pfetch proxy and server middleware);
|
|
73
|
+
* bigger ones get a `413`. Default 10 MiB (10485760); `false` turns it off.
|
|
74
|
+
*/
|
|
75
|
+
bodyLimit?: number | false;
|
|
76
|
+
/**
|
|
77
|
+
* Hostnames (`app.example.com`, `app.example.com:8080` or `*.example.com` for any subdomain) the server answers to;
|
|
78
|
+
* requests with another `Host` get a `400`. Not set by default: any host is accepted.
|
|
79
|
+
*/
|
|
80
|
+
allowedHosts?: string[];
|
|
81
|
+
}
|
|
82
|
+
interface ResolvedSecurity {
|
|
83
|
+
csp?: CspConfig;
|
|
84
|
+
headers: Record<string, string>;
|
|
85
|
+
csrf: {
|
|
86
|
+
allowedOrigins: string[];
|
|
87
|
+
publicOrigin?: string;
|
|
88
|
+
} | false;
|
|
89
|
+
bodyLimit: number | false;
|
|
90
|
+
allowedHosts?: string[];
|
|
91
|
+
}
|
|
92
|
+
/** What a `routeRules` entry may change: each option replaces (`csp`, `csrf`, `bodyLimit`) or is applied on top of (`headers`) the global one */
|
|
93
|
+
interface RouteSecurityConfig {
|
|
94
|
+
/** CSP of the matching pages instead of the global one. `false` sends none */
|
|
95
|
+
csp?: CspConfig | false;
|
|
96
|
+
/** Applied on top of the global headers (`false` value removes one, `false` alone removes them all) */
|
|
97
|
+
headers?: boolean | Record<string, string | false>;
|
|
98
|
+
/** CSRF protection of matching API / proxy paths instead of the global one. `false` turns it off */
|
|
99
|
+
csrf?: boolean | CsrfConfig;
|
|
100
|
+
/** Request body limit in bytes of matching paths instead of the global one. `false` turns it off */
|
|
101
|
+
bodyLimit?: number | false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Options that apply to every page whose URL matches a `routeRules` pattern */
|
|
105
|
+
interface RouteRule {
|
|
106
|
+
/** `false` serves the client-only shell for matching pages, even when `ssr` is on globally */
|
|
107
|
+
ssr?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* How the doofpi client reaches the API on matching pages, instead of `doofpi.fetch`, e.g. `"sfetch"` to keep the
|
|
110
|
+
* API out of the browser for `/admin/**`. Needs `doofpi.url` unless it is `lfetch`; `sfetch` needs SSR.
|
|
111
|
+
* `useDoofpi()` picks it from the page it is called on, so call it in that page's `setup()`.
|
|
112
|
+
*/
|
|
113
|
+
fetch?: FetchMode;
|
|
114
|
+
/**
|
|
115
|
+
* Overrides the global `security` options for matching URL paths (pages, and the API / proxy for `csrf`).
|
|
116
|
+
* Server-only: never sent to the browser.
|
|
117
|
+
*/
|
|
118
|
+
security?: RouteSecurityConfig;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Keyed by URL path pattern: `/about` (exact), `/users/*` (one segment) or `/admin/**` (the path itself and
|
|
122
|
+
* everything below it). When several patterns match, the most specific one (the longest) wins per option.
|
|
123
|
+
*/
|
|
124
|
+
type RouteRules = Record<string, RouteRule>;
|
|
125
|
+
|
|
126
|
+
export { FETCH_MODES as d };
|
|
127
|
+
export type { CspConfig as C, FetchMode as F, HeadConfig as H, RouteRules as R, SecurityConfig as S, CspDirectiveName as a, CspDirectiveValue as b, CsrfConfig as c, HeadInput as e, HeadTag as f, RouteRule as g, ResolvedHead as h, ResolvedSecurity as i };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NoofpiLayout
|
|
3
|
+
} from "../chunk-MTWSTW7V.js";
|
|
4
|
+
import "../chunk-Y3NBZ6DW.js";
|
|
5
|
+
|
|
6
|
+
// src/runtime/default-app.ts
|
|
7
|
+
import { defineComponent, h } from "vue";
|
|
8
|
+
var DefaultApp = defineComponent({
|
|
9
|
+
name: "NoofpiApp",
|
|
10
|
+
render: () => h(NoofpiLayout)
|
|
11
|
+
});
|
|
12
|
+
var default_app_default = DefaultApp;
|
|
13
|
+
export {
|
|
14
|
+
default_app_default as default
|
|
15
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNoofpiApp
|
|
3
|
+
} from "../chunk-X34Y6ESE.js";
|
|
4
|
+
import "../chunk-6OWKWAIW.js";
|
|
5
|
+
import "../chunk-ELXCFUA4.js";
|
|
6
|
+
import "../chunk-EZPJF4D4.js";
|
|
7
|
+
import "../chunk-G35DW4NA.js";
|
|
8
|
+
import "../chunk-FIJJ3EGL.js";
|
|
9
|
+
|
|
10
|
+
// src/runtime/entry-client.ts
|
|
11
|
+
import { publicConfig } from "virtual:noofpi/config";
|
|
12
|
+
import routeMiddleware from "virtual:noofpi/middleware";
|
|
13
|
+
|
|
14
|
+
// src/runtime/prefetch.ts
|
|
15
|
+
function linkPrefetchTarget(target, origin) {
|
|
16
|
+
const anchor = target?.closest?.("a[href]");
|
|
17
|
+
if (!anchor || anchor.hasAttribute("download") || anchor.hasAttribute("data-no-prefetch") || anchor.target && anchor.target !== "_self")
|
|
18
|
+
return void 0;
|
|
19
|
+
let url;
|
|
20
|
+
try {
|
|
21
|
+
url = new URL(anchor.href, origin);
|
|
22
|
+
} catch {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
if (url.origin !== origin) return void 0;
|
|
26
|
+
return url.pathname + url.search;
|
|
27
|
+
}
|
|
28
|
+
function listenForPrefetch(prefetch) {
|
|
29
|
+
const connection = navigator.connection;
|
|
30
|
+
if (connection?.saveData) return () => {
|
|
31
|
+
};
|
|
32
|
+
const onIntent = (event) => {
|
|
33
|
+
const href = linkPrefetchTarget(event.target, location.origin);
|
|
34
|
+
if (href) prefetch(href).catch(() => {
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const events = ["mouseover", "focusin", "touchstart"];
|
|
38
|
+
for (const name of events)
|
|
39
|
+
document.addEventListener(name, onIntent, { passive: true });
|
|
40
|
+
return () => {
|
|
41
|
+
for (const name of events) document.removeEventListener(name, onIntent);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/runtime/entry-client.ts
|
|
46
|
+
async function mount() {
|
|
47
|
+
const { app, router, payload, error, log, loaders, i18n } = createNoofpiApp({
|
|
48
|
+
server: false
|
|
49
|
+
});
|
|
50
|
+
await i18n?.ready;
|
|
51
|
+
if (import.meta.env.DEV && publicConfig.devtools) {
|
|
52
|
+
const { mountDevtools } = await import("../devtools-KTDSD5PR.js");
|
|
53
|
+
mountDevtools({
|
|
54
|
+
router,
|
|
55
|
+
config: publicConfig,
|
|
56
|
+
middlewareFiles: Object.keys(routeMiddleware),
|
|
57
|
+
requests: log
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
await router.isReady().catch((failure) => {
|
|
61
|
+
if (!error.value) throw failure;
|
|
62
|
+
});
|
|
63
|
+
app.mount("#app");
|
|
64
|
+
listenForPrefetch(loaders.prefetch);
|
|
65
|
+
payload.data = {};
|
|
66
|
+
payload.errors = {};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
mount
|
|
70
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectState,
|
|
3
|
+
createNoofpiApp,
|
|
4
|
+
notFoundError,
|
|
5
|
+
setServerStateSource,
|
|
6
|
+
snapshotEntries
|
|
7
|
+
} from "../chunk-X34Y6ESE.js";
|
|
8
|
+
import "../chunk-6OWKWAIW.js";
|
|
9
|
+
import "../chunk-ELXCFUA4.js";
|
|
10
|
+
import {
|
|
11
|
+
isNoofpiError,
|
|
12
|
+
toErrorData
|
|
13
|
+
} from "../chunk-EZPJF4D4.js";
|
|
14
|
+
import "../chunk-G35DW4NA.js";
|
|
15
|
+
import "../chunk-FIJJ3EGL.js";
|
|
16
|
+
|
|
17
|
+
// src/runtime/entry-server.ts
|
|
18
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
19
|
+
import { renderToString } from "vue/server-renderer";
|
|
20
|
+
import ErrorPage from "virtual:noofpi/error";
|
|
21
|
+
var requestScope = new AsyncLocalStorage();
|
|
22
|
+
setServerStateSource(() => requestScope.getStore()?.payload);
|
|
23
|
+
async function renderRoute(url, ctx) {
|
|
24
|
+
const { app, router, payload, head, error, log, i18n } = createNoofpiApp({
|
|
25
|
+
server: true,
|
|
26
|
+
...ctx
|
|
27
|
+
});
|
|
28
|
+
requestScope.getStore().payload = payload;
|
|
29
|
+
const failure = await router.push(url);
|
|
30
|
+
await router.isReady();
|
|
31
|
+
if (failure) {
|
|
32
|
+
if (!ErrorPage) return { html: "", status: 404 };
|
|
33
|
+
error.value = notFoundError(url);
|
|
34
|
+
} else {
|
|
35
|
+
const requested = router.resolve(url).fullPath;
|
|
36
|
+
const current = router.currentRoute.value.fullPath;
|
|
37
|
+
if (current !== requested) {
|
|
38
|
+
return {
|
|
39
|
+
html: "",
|
|
40
|
+
status: 302,
|
|
41
|
+
// One leading slash only, so a redirect can never turn into a protocol-relative (external) URL
|
|
42
|
+
redirect: "/" + current.replace(/^\/+/, "")
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (ErrorPage && !router.currentRoute.value.matched.length)
|
|
46
|
+
error.value = notFoundError(url);
|
|
47
|
+
}
|
|
48
|
+
const failures = [];
|
|
49
|
+
if (ErrorPage)
|
|
50
|
+
app.config.errorHandler = (failure2) => void failures.push(failure2);
|
|
51
|
+
const html = await renderToString(app);
|
|
52
|
+
if (failures.length) throw failures[0];
|
|
53
|
+
return {
|
|
54
|
+
html,
|
|
55
|
+
status: error.value ? error.value.statusCode : router.currentRoute.value.matched.length ? 200 : 404,
|
|
56
|
+
payload: {
|
|
57
|
+
data: payload.data,
|
|
58
|
+
errors: payload.errors,
|
|
59
|
+
state: collectState(payload),
|
|
60
|
+
...error.value ? { error: error.value } : {},
|
|
61
|
+
...i18n ? { locale: i18n.locale.value } : {},
|
|
62
|
+
...log ? { requests: snapshotEntries(log) } : {}
|
|
63
|
+
},
|
|
64
|
+
// Resolved after rendering, so titles that depend on fetched data are included
|
|
65
|
+
head: head.resolve()
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function renderErrorPage(url, ctx, failure) {
|
|
69
|
+
const { app, payload, head, error, log, i18n } = createNoofpiApp({
|
|
70
|
+
server: true,
|
|
71
|
+
...ctx
|
|
72
|
+
});
|
|
73
|
+
requestScope.getStore().payload = payload;
|
|
74
|
+
error.value = toErrorData(failure, url);
|
|
75
|
+
const failures = [];
|
|
76
|
+
app.config.errorHandler = (inner) => void failures.push(inner);
|
|
77
|
+
const html = await renderToString(app);
|
|
78
|
+
if (failures.length) throw failures[0];
|
|
79
|
+
return {
|
|
80
|
+
html,
|
|
81
|
+
status: error.value.statusCode,
|
|
82
|
+
// Errors made with `createError()` are intended; anything else is a bug the server has to report
|
|
83
|
+
...isNoofpiError(failure) ? {} : { error: failure },
|
|
84
|
+
payload: {
|
|
85
|
+
data: {},
|
|
86
|
+
errors: {},
|
|
87
|
+
state: collectState(payload),
|
|
88
|
+
error: error.value,
|
|
89
|
+
...i18n ? { locale: i18n.locale.value } : {},
|
|
90
|
+
...log ? { requests: snapshotEntries(log) } : {}
|
|
91
|
+
},
|
|
92
|
+
head: head.resolve()
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function render(url, ctx) {
|
|
96
|
+
return requestScope.run({}, async () => {
|
|
97
|
+
try {
|
|
98
|
+
return await renderRoute(url, ctx);
|
|
99
|
+
} catch (failure) {
|
|
100
|
+
if (!ErrorPage) throw failure;
|
|
101
|
+
return await renderErrorPage(url, ctx, failure);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
render
|
|
107
|
+
};
|