@galatiq/demo-gateway-middleware 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/index.js +40 -0
  4. package/package.json +35 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Galatiq AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @galatiq/demo-gateway-middleware
2
+
3
+ Vercel Edge Middleware that admits only requests from Galatiq's [demo-gateway](https://github.com/galatiq-ai/galatiq-internal-platform-demo-gateway) via a shared header secret. Drop it into any Vercel-hosted Galatiq client demo to gate the public `*.vercel.app` URL behind gateway auth.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @galatiq/demo-gateway-middleware
9
+ ```
10
+
11
+ ## Use
12
+
13
+ Create `middleware.js` (or `middleware.ts`) at the **root** of the Vercel project:
14
+
15
+ ```js
16
+ export { default, config } from '@galatiq/demo-gateway-middleware';
17
+ ```
18
+
19
+ That's the whole file. Both `default` (the handler) and `config` (the matcher) come from the package — Vercel auto-discovers them.
20
+
21
+ ## Configure
22
+
23
+ Set these env vars in the Vercel project — **Settings → Environment Variables**:
24
+
25
+ | Name | Value | Required |
26
+ |---|---|---|
27
+ | `GATEWAY_SECRET` | A long random string. Must match the value stored on this demo's row in demo-gateway's admin UI. Generate with `openssl rand -hex 32`. | ✅ |
28
+ | `GATEWAY_URL` | Override the default gateway URL. Defaults to `https://galatiq-demo-gateway-production.up.railway.app`. | optional |
29
+
30
+ Apply both to **Production** (and **Preview** if you want gating there).
31
+
32
+ ## How it works
33
+
34
+ ```
35
+ Browser ──► demo-gateway (auth)
36
+ │ proxy fetch + x-demo-gateway-secret: <secret>
37
+
38
+ *.vercel.app ──► middleware verifies header ──► demo
39
+
40
+ Browser ──► *.vercel.app directly ──► middleware sees no header ──► 302 to /login
41
+ ```
42
+
43
+ - Request carries `x-demo-gateway-secret: <secret>` matching `GATEWAY_SECRET` → request passes through to the demo.
44
+ - Header missing or wrong → 302 redirect to `${GATEWAY_URL}/login`.
45
+ - `GATEWAY_SECRET` env var not set → middleware fails **closed** with a 503 `Demo gateway not configured`. The demo is never served unprotected.
46
+
47
+ The matcher gates every path except Vercel internals (`/_vercel/*`) and `/favicon.ico`. That includes static assets (`/js/*`, `/css/*`, etc.) and API routes (`/api/*`) — everything goes through gateway auth.
48
+
49
+ ## Rotating the secret
50
+
51
+ 1. Generate a new value: `openssl rand -hex 32`.
52
+ 2. Update `GATEWAY_SECRET` in Vercel → redeploy the demo.
53
+ 3. Update the demo's row in demo-gateway's admin UI → **Save Changes**.
54
+
55
+ If you update Vercel first, gateway requests carrying the old secret get rejected until you also update the admin UI. Plan for ~30 seconds of "Demo unavailable" during a rotation, or update the admin UI first.
56
+
57
+ ## Versioning
58
+
59
+ Standard SemVer:
60
+
61
+ - **major** — change to the wire protocol (header name, redirect target shape) or breaking API change for consumers.
62
+ - **minor** — new optional behavior, backwards compatible.
63
+ - **patch** — bug fixes.
64
+
65
+ ## License
66
+
67
+ MIT
package/index.js ADDED
@@ -0,0 +1,40 @@
1
+ // @galatiq/demo-gateway-middleware
2
+ //
3
+ // Vercel Edge Middleware for Galatiq client demos. Admits only requests
4
+ // carrying a matching `x-demo-gateway-secret` header (injected by
5
+ // demo-gateway on every outbound proxy fetch). Direct visitors to the
6
+ // public *.vercel.app URL get a 302 to demo-gateway's login page.
7
+ //
8
+ // Required env vars on the consuming demo's Vercel project:
9
+ // GATEWAY_SECRET — long random string. Must match the value stored on
10
+ // this demo's row in demo-gateway's admin UI.
11
+ // GATEWAY_URL — (optional) override the default gateway URL.
12
+
13
+ export const config = {
14
+ // Gate every path except Vercel internals and the favicon. Static assets
15
+ // (/js/*, /css/*, etc.) are gated too — they're served only via the
16
+ // gateway proxy, which injects the secret on every fetch.
17
+ matcher: '/((?!_vercel|favicon\\.ico).*)',
18
+ };
19
+
20
+ /**
21
+ * @param {Request} request
22
+ * @returns {Response | void}
23
+ */
24
+ export default function middleware(request) {
25
+ const secret = process.env.GATEWAY_SECRET;
26
+ const gatewayUrl =
27
+ process.env.GATEWAY_URL ||
28
+ 'https://galatiq-demo-gateway-production.up.railway.app';
29
+
30
+ // Fail closed if the secret env var is missing — never serve unprotected.
31
+ if (!secret) {
32
+ return new Response('Demo gateway not configured', { status: 503 });
33
+ }
34
+
35
+ if (request.headers.get('x-demo-gateway-secret') === secret) {
36
+ return; // pass through to the demo
37
+ }
38
+
39
+ return Response.redirect(`${gatewayUrl}/login`, 302);
40
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@galatiq/demo-gateway-middleware",
3
+ "version": "1.0.0",
4
+ "description": "Vercel Edge Middleware that admits only requests from Galatiq's demo-gateway via a shared header secret.",
5
+ "type": "module",
6
+ "main": "./index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "engines": {
16
+ "node": ">=18"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/galatiq-ai/galatiq-internal-service-demo-gateway-middleware.git"
21
+ },
22
+ "homepage": "https://github.com/galatiq-ai/galatiq-internal-service-demo-gateway-middleware#readme",
23
+ "bugs": "https://github.com/galatiq-ai/galatiq-internal-service-demo-gateway-middleware/issues",
24
+ "license": "MIT",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "keywords": [
29
+ "vercel",
30
+ "edge",
31
+ "middleware",
32
+ "galatiq",
33
+ "demo-gateway"
34
+ ]
35
+ }