Skip to content

Commit c10d2ae

Browse files
authored
Merge pull request #8043 from QwikDev/move-origin-doc
chore(docs): Move origin doc
2 parents 8883975 + f098f91 commit c10d2ae

File tree

3 files changed

+54
-59
lines changed

3 files changed

+54
-59
lines changed

packages/docs/src/components/on-this-page/on-this-page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const OnThisPage = component$(() => {
198198
{contentHeadings.map((h) => (
199199
<li
200200
key={h.id}
201+
style={{ paddingLeft: `${(h.level - 2) * 16}px` }}
201202
class={`${
202203
theme.theme === 'light'
203204
? 'hover:bg-[var(--qwik-light-blue)]'
@@ -207,10 +208,7 @@ export const OnThisPage = component$(() => {
207208
{activeId.value === h.id ? (
208209
<span class="on-this-page-item">{h.text}</span>
209210
) : (
210-
<Link
211-
href={`#${h.id}`}
212-
class={`${h.level > 2 ? 'ml-0' : null} on-this-page-item`}
213-
>
211+
<Link href={`#${h.id}`} class={`on-this-page-item`}>
214212
{h.text}
215213
</Link>
216214
)}

packages/docs/src/routes/api/qwik-city-middleware-node/index.mdx

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -131,61 +131,6 @@ true
131131

132132
</td><td>
133133

134-
135-
<tr><td colspan="4">
136-
137-
### getOriginrecommended usage and examples
138-
139-
If your application is running behind a proxy (for example Cloud Run, API Gateway, or a load balancer) or in an environment where the public origin is known ahead of time, provide a `getOrigin` function to reliably reconstruct the origin (scheme + host + optional port). This is used to resolve relative URLs and to validate the request origin when performing CSRF checks.
140-
141-
By default the middleware will use the `ORIGIN` environment variable when set. If `ORIGIN` is not present, the middleware will attempt to derive the origin from the incoming request (not recommended for production).
142-
143-
Examples
144-
145-
1) Simple static origin from environment (recommended for production if you know the origin):
146-
147-
```ts
148-
// Provide ORIGIN=https://example.com in your environment
149-
createQwikCity({
150-
origin: process.env.ORIGIN,
151-
});
152-
```
153-
154-
2) Compute origin using forwarded headers (common when behind proxies). Use the headers your proxy provides, e.g. `X-Forwarded-Proto` and `X-Forwarded-Host`:
155-
156-
```ts
157-
createQwikCity({
158-
getOrigin(req) {
159-
const proto = req.headers['x-forwarded-proto'] as string | undefined;
160-
const host = req.headers['x-forwarded-host'] as string | undefined || (req.headers.host as string | undefined);
161-
if (!host) return null;
162-
return `${proto ?? 'https'}://${host}`;
163-
}
164-
});
165-
```
166-
167-
3) Example: Cloud Run adapter (reconstructs the origin from forwarded headers)
168-
169-
```ts
170-
// starters/adapters/cloud-run entry (illustrative)
171-
createQwikCity({
172-
getOrigin(req) {
173-
// Cloud Run sets X-Forwarded-Proto and Host headers
174-
const proto = req.headers['x-forwarded-proto'] as string | undefined;
175-
const host = (req.headers['host'] || req.headers['x-forwarded-host']) as string | undefined;
176-
if (!host) return null;
177-
return `${proto ?? 'https'}://${host}`;
178-
}
179-
});
180-
```
181-
182-
Notes and best practices
183-
184-
- Prefer a static `ORIGIN` environment variable for production whenever possible. It is the most reliable and secure option.
185-
- When relying on forwarded headers, ensure your proxy/ALB sets them and consider locking the trusted proxy list so attackers cannot spoof them.
186-
- Return `null` from `getOrigin` when the origin cannot be determined; the middleware will fall back to deriving it from the request.
187-
188-
</td></tr>
189134
_(Optional)_
190135

191136
</td></tr>

packages/docs/src/routes/docs/deployments/index.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,55 @@ The various deployment platforms have different ways of configuring this, and th
127127
To verify proper caching, you can visit your site and open the developer tools to inspect the network requests. When you reload the page, you should see that all requests for assets are coming from the browser cache and are not contacting the server. Even a `304 Not Modified` response is not good enough, because it means that the browser is still unsure that the content is cached.
128128

129129
⚠️ **Note**: If your app uses [`compiled-i18n`](https://github.com/wmertens/compiled-i18n) or [`qwik-speak`](https://github.com/robisim74/qwik-speak), then translated bundles (`build/[locale]/*.js`) can retain identical filenames between builds even when translations change. Consider how long you want to cache these files for so users get the latest translations.
130+
131+
## Origin
132+
133+
We recommend setting the `ORIGIN` environment variable to the origin of your site (e.g. `https://example.com/`). This is used to resolve relative URLs and to validate the request origin when performing CSRF checks.
134+
135+
However, if the origin of your application is not static because you're hosting multiple sites, the Node.js based middleware provides a `getOrigin()` callback option to reliably reconstruct the origin (scheme + host + optional port).
136+
137+
138+
### Examples
139+
140+
1) Simple static origin from environment (recommended for production if you know the origin):
141+
142+
```ts
143+
// Provide ORIGIN=https://example.com in your environment
144+
createQwikCity({
145+
origin: process.env.ORIGIN,
146+
});
147+
```
148+
149+
2) Compute origin using forwarded headers (common when behind proxies). Use the headers your proxy provides, e.g. `X-Forwarded-Proto` and `X-Forwarded-Host`:
150+
151+
```ts
152+
createQwikCity({
153+
getOrigin(req) {
154+
const proto = req.headers['x-forwarded-proto'] as string | undefined;
155+
const host = req.headers['x-forwarded-host'] as string | undefined || (req.headers.host as string | undefined);
156+
if (!host) return null;
157+
return `${proto ?? 'https'}://${host}`;
158+
}
159+
});
160+
```
161+
162+
3) Example: Cloud Run adapter (reconstructs the origin from forwarded headers)
163+
164+
```ts
165+
// starters/adapters/cloud-run entry (illustrative)
166+
createQwikCity({
167+
getOrigin(req) {
168+
// Cloud Run sets X-Forwarded-Proto and Host headers
169+
const proto = req.headers['x-forwarded-proto'] as string | undefined;
170+
const host = (req.headers['host'] || req.headers['x-forwarded-host']) as string | undefined;
171+
if (!host) return null;
172+
return `${proto ?? 'https'}://${host}`;
173+
}
174+
});
175+
```
176+
177+
### Notes and best practices
178+
179+
- Prefer a static `ORIGIN` environment variable for production whenever possible. It is the most reliable and secure option.
180+
- When relying on forwarded headers, ensure your proxy/ALB sets them and consider locking the trusted proxy list so attackers cannot spoof them.
181+
- Return `null` from `getOrigin` when the origin cannot be determined; the middleware will fall back to deriving it from the request.

0 commit comments

Comments
 (0)