@stacksjs/defaults 0.75.663 → 0.75.667

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,141 @@
1
+ import type { ServerConfig } from '@stacksjs/types'
2
+
3
+ /**
4
+ * **Server Configuration**
5
+ *
6
+ * This configuration defines how the views server behaves in the split
7
+ * views/API topology, shared by `buddy dev` and `buddy serve`. Because Stacks
8
+ * is fully-typed, you may hover any of the options below and the definitions
9
+ * will be provided. In case you have any questions, feel free to reach out via
10
+ * Discord or GitHub Discussions.
11
+ */
12
+ export default {
13
+ // Opt in after publishing the native Request model and migrating its table.
14
+ captureRequests: false,
15
+ /**
16
+ * **API Proxy**
17
+ *
18
+ * The views server renders stx pages and forwards everything else to the API
19
+ * process. By default "everything else" means the `/api/**` prefix plus the
20
+ * mutating verbs (POST/PUT/PATCH/DELETE), which never match a page render.
21
+ *
22
+ * A plain `GET` route declared at the root on the API process is therefore
23
+ * not reachable unless you say so here. That is what these options are for:
24
+ *
25
+ * ```ts
26
+ * proxy: {
27
+ * paths: ['/health', '/me'],
28
+ * prefixes: ['/oauth/'],
29
+ * }
30
+ * ```
31
+ *
32
+ * `buddy dev` prints the effective rules at boot, so you can see what will
33
+ * be forwarded without guessing at a 404.
34
+ *
35
+ * One caveat worth knowing before you add a path: stx runs its request hook
36
+ * before static file serving, so a path listed here shadows a `public/` file
37
+ * of the same name. Listing `/script.js` makes `public/script.js`
38
+ * unreachable.
39
+ */
40
+ proxy: {
41
+ prefixes: [],
42
+ paths: [],
43
+ },
44
+
45
+ /**
46
+ * **Redirects**
47
+ *
48
+ * Old URLs and where they go now. Every site that replaces an older one
49
+ * inherits its URLs — they are in search indexes, in other people's links,
50
+ * and on printed material — and a 301 is the only thing that carries their
51
+ * standing across to the new page.
52
+ *
53
+ * ```ts
54
+ * redirects: {
55
+ * '/old-page': '/new-page',
56
+ * '/summer-sale': { to: '/specials', status: 302 },
57
+ * '/docs': { to: 'https://docs.example.com', preserveQuery: false },
58
+ * }
59
+ * ```
60
+ *
61
+ * A rule written as `/section/*` claims that subtree instead, appending
62
+ * whatever followed the prefix to the target — `'/dashboard/*':
63
+ * 'https://dash.example.com'` sends `/dashboard/events/42` to
64
+ * `https://dash.example.com/events/42`. It is the one wildcard form there
65
+ * is: moving a section whose pages are dynamic cannot be written as a list
66
+ * of exact rules. An exact rule always wins over a subtree one.
67
+ *
68
+ * Matching is otherwise exact on the path, ignoring a trailing slash, and the query
69
+ * string is carried over unless you say otherwise. Rules are answered before
70
+ * a page is looked for and before `public/` is searched, so — as with
71
+ * `proxy.paths` — a rule shadows a static file of the same name. Anything
72
+ * under `/api/` is ignored, and a rule pointing at itself is dropped rather
73
+ * than looping the browser.
74
+ *
75
+ * `buddy dev` prints the effective rules at boot.
76
+ */
77
+ redirects: {},
78
+
79
+ /**
80
+ * **Domains**
81
+ *
82
+ * Hosts whose home page is a page of the site.
83
+ *
84
+ * ```ts
85
+ * domains: {
86
+ * '{username}.example.com': '/{username}',
87
+ * }
88
+ * ```
89
+ *
90
+ * `chris.example.com` then renders what `example.com/chris` renders — the
91
+ * same `resources/views/[username].stx`, with the same params — while the
92
+ * address bar keeps the host: a profile, a team or a shop with a domain of
93
+ * its own. Only the host's root is routed; its other paths are the site's
94
+ * own. A `{name}` label matches one DNS label.
95
+ *
96
+ * `{ to: '/{username}', elsewhere: 'https://example.com' }` keeps the root
97
+ * as the page and redirects the host's other pages to the main site, so a
98
+ * visitor browses and signs in on one origin.
99
+ *
100
+ * The hostnames still have to reach the server: with ts-cloud, list
101
+ * `*.example.com` in the site's `aliases` in `config/cloud.ts`.
102
+ */
103
+ domains: {},
104
+
105
+ /**
106
+ * **Security headers**
107
+ *
108
+ * Rendered pages carry `X-Frame-Options: SAMEORIGIN`,
109
+ * `X-Content-Type-Options: nosniff` and
110
+ * `Referrer-Policy: strict-origin-when-cross-origin`, the same three the
111
+ * API already sent. None of them can be set from a template:
112
+ * `X-Frame-Options` has no `<meta>` equivalent, and CSP `frame-ancestors`
113
+ * is ignored when set that way.
114
+ *
115
+ * `embeddable` lists the paths another origin is allowed to frame. Those
116
+ * paths omit `X-Frame-Options` and keep everything else:
117
+ *
118
+ * ```ts
119
+ * security: {
120
+ * embeddable: ['/embed/', '/share/card'],
121
+ * }
122
+ * ```
123
+ *
124
+ * An entry ending in `/` is a prefix, anything else is an exact path.
125
+ * `buddy dev` and `buddy serve` both print the list at boot, because a page
126
+ * that can be framed is a deliberate exception worth seeing.
127
+ *
128
+ * Two headers are deliberately NOT sent on pages. A `STACKS_CSP` policy is
129
+ * not, because it has only ever reached JSON responses and a blanket policy
130
+ * breaks inline stx script bootstrapping, Stripe iframes and OAuth popups.
131
+ * `Strict-Transport-Security` is not, because `buddy serve` treats itself as
132
+ * production even on a laptop, and HSTS on localhost pins that host to
133
+ * HTTPS in your browser for a year.
134
+ *
135
+ * `STACKS_SECURITY_HEADERS_DISABLE=true` turns the whole set off, for a
136
+ * deployment behind a proxy that injects its own.
137
+ */
138
+ security: {
139
+ embeddable: [],
140
+ },
141
+ } satisfies ServerConfig