Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
node-version: '22'
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install --frozen-lockfile

- name: Run proxy regression test
run: pnpm test:proxy

- name: Run ESLint
run: pnpm lint
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"test:proxy": "node --no-warnings --experimental-strip-types --test tests/publicProxyPaths.test.mjs",
"dev": "next dev",
"dev:insecure": "NODE_TLS_REJECT_UNAUTHORIZED=0 next dev",
"build": "next build",
Expand Down
7 changes: 2 additions & 5 deletions src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { type NextRequest, NextResponse } from "next/server";
import { COOKIE_KEYS } from "@/shared/constants/cookies";
import { isPublicProxyPath } from "@/shared/lib/publicProxyPaths";

export async function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
const accessToken = request.cookies.get(COOKIE_KEYS.ACCESS_TOKEN)?.value;

if (
pathname.startsWith("/api/") ||
pathname === "/sign-in" ||
pathname === "/app-download"
) {
if (isPublicProxyPath(pathname)) {
return NextResponse.next();
}

Expand Down
10 changes: 10 additions & 0 deletions src/shared/lib/publicProxyPaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const PUBLIC_PROXY_PATHS = new Set([
"/sign-in",
"/app-download",
"/manifest.webmanifest",
"/firebase-messaging-sw.js",
]);

export function isPublicProxyPath(pathname: string) {
return pathname.startsWith("/api/") || PUBLIC_PROXY_PATHS.has(pathname);
}
15 changes: 15 additions & 0 deletions tests/publicProxyPaths.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import assert from "node:assert/strict";
import test from "node:test";

import { isPublicProxyPath } from "../src/shared/lib/publicProxyPaths.ts";

test("allows public PWA assets through the authentication proxy", () => {
for (const pathname of [
"/manifest.webmanifest",
"/firebase-messaging-sw.js",
]) {
assert.equal(isPublicProxyPath(pathname), true, pathname);
}

assert.equal(isPublicProxyPath("/machines"), false);
});
Loading