highseat 0.1.0-alpha.2 → 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.
- package/README.md +49 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Highseat analytics for JavaScript: typed tracking, a first-party proxy and framework components.
|
|
4
4
|
|
|
5
|
-
> **Pre-release.** The `alpha` versions can change shape between releases.
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
npm install highseat
|
|
8
|
+
npm install highseat
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
## Entry points
|
|
@@ -154,6 +152,54 @@ Next.js loads `next.config.ts` with `require`, and the package is ES modules onl
|
|
|
154
152
|
|
|
155
153
|
`withHighseat()` rewrites `HIGHSEAT_PATH` to the route handler inside the app, so the visitor's IP survives and the route file never moves. Pass `{ route: "/stats" }` for a handler elsewhere. Without `HIGHSEAT_PATH`, `next dev` and `next build` warn once and leave the rewrite out, and `next typegen` runs as usual. Set the variable for the build as well as the server: the rewrite is written at build time. Off Vercel, the outermost proxy that sets the header decides the preset: `"cloudflare"` behind a proxied Cloudflare record, even with nginx or Traefik in between, and `"nginx"` behind nginx alone.
|
|
156
154
|
|
|
155
|
+
### TanStack Start
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
// src/server.ts
|
|
159
|
+
import handler, { createServerEntry } from "@tanstack/react-start/server-entry"
|
|
160
|
+
import { createProxy } from "highseat/proxy"
|
|
161
|
+
|
|
162
|
+
const proxy = createProxy({
|
|
163
|
+
clientIp: "cloudflare",
|
|
164
|
+
fallback: request => handler.fetch(request),
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
export default createServerEntry({ fetch: request => proxy(request) })
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
// vite.config.ts
|
|
172
|
+
import { defineConfig, loadEnv } from "vite"
|
|
173
|
+
|
|
174
|
+
export default defineConfig(({ mode }) => ({
|
|
175
|
+
// Loads HIGHSEAT_PATH alone, so the site secret beside it never reaches the bundle.
|
|
176
|
+
define: {
|
|
177
|
+
"import.meta.env.HIGHSEAT_PATH": JSON.stringify(
|
|
178
|
+
loadEnv(mode, process.cwd(), "HIGHSEAT_PATH").HIGHSEAT_PATH,
|
|
179
|
+
),
|
|
180
|
+
},
|
|
181
|
+
// Your own config.
|
|
182
|
+
}))
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
// src/routes/__root.tsx
|
|
187
|
+
<Highseat site={import.meta.env.VITE_HIGHSEAT_SITE} src={import.meta.env.HIGHSEAT_PATH} />
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The server entry answers `HIGHSEAT_PATH` with the proxy and hands every other request to the app. A file route named after the path does not work: a catch-all route such as `$id` matches it first. The `define` gives the browser the same path, so set `HIGHSEAT_PATH` for the build as well as the server, as a build argument in a Docker build. Pick the preset for the outermost proxy that sets the header, as for Next.js.
|
|
191
|
+
|
|
192
|
+
`fallback` receives the request alone, so the app loses the options the server entry was called with. An app that reads them routes the path itself, with a proxy created without `fallback`:
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
export default createServerEntry({
|
|
196
|
+
fetch: (request, options) =>
|
|
197
|
+
new URL(request.url).pathname === process.env.HIGHSEAT_PATH
|
|
198
|
+
? proxy(request)
|
|
199
|
+
: handler.fetch(request, options),
|
|
200
|
+
})
|
|
201
|
+
```
|
|
202
|
+
|
|
157
203
|
### Cloudflare Worker
|
|
158
204
|
|
|
159
205
|
```ts
|