feat: disable rate limiting env var

This commit is contained in:
Nicolas Meienberger 2026-01-11 08:44:12 +01:00
parent 763d426ba9
commit a98ab958ef
6 changed files with 43 additions and 15 deletions

View file

@ -1,4 +1,6 @@
name: E2E Tests name: E2E Tests
permissions:
contents: read
on: on:
push: push:
branches: [ main ] branches: [ main ]
@ -17,9 +19,30 @@ jobs:
- name: Install dependencies - name: Install dependencies
uses: "./.github/actions/install-dependencies" uses: "./.github/actions/install-dependencies"
- name: Get Playwright version
id: playwright-version
shell: bash
run: |
playwright_version=$(bun -e "console.log((await Bun.file('./package.json').json()).devDependencies['@playwright/test'])")
echo "version=$playwright_version" >> $GITHUB_OUTPUT
- name: Cache Playwright Browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright Browsers - name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: bunx playwright install --with-deps run: bunx playwright install --with-deps
- name: Install Playwright System Dependencies
if: steps.playwright-cache.outputs.cache-hit == 'true'
run: bunx playwright install-deps
- name: Prepare environment - name: Prepare environment
run: | run: |
mkdir -p data mkdir -p data

View file

@ -37,7 +37,7 @@ export const scalarDescriptor = Scalar({
}); });
export const createApp = () => { export const createApp = () => {
const app = new Hono(); const app = new Hono().use(secureHeaders());
if (config.trustedOrigins) { if (config.trustedOrigins) {
app.use(cors({ origin: config.trustedOrigins })); app.use(cors({ origin: config.trustedOrigins }));
@ -47,9 +47,8 @@ export const createApp = () => {
app.use(honoLogger()); app.use(honoLogger());
} }
app if (!config.disableRateLimiting) {
.use(secureHeaders()) app.use(
.use(
rateLimiter({ rateLimiter({
windowMs: 60 * 5 * 1000, windowMs: 60 * 5 * 1000,
limit: 1000, limit: 1000,
@ -58,7 +57,10 @@ export const createApp = () => {
return config.__prod__ === false; return config.__prod__ === false;
}, },
}), }),
) );
}
app
.get("healthcheck", (c) => c.json({ status: "ok" })) .get("healthcheck", (c) => c.json({ status: "ok" }))
.route("/api/v1/auth", authController) .route("/api/v1/auth", authController)
.route("/api/v1/volumes", volumeController) .route("/api/v1/volumes", volumeController)

View file

@ -33,6 +33,7 @@ const envSchema = type({
MIGRATIONS_PATH: "string?", MIGRATIONS_PATH: "string?",
APP_VERSION: "string = 'dev'", APP_VERSION: "string = 'dev'",
TRUSTED_ORIGINS: "string?", TRUSTED_ORIGINS: "string?",
DISABLE_RATE_LIMITING: 'string = "false"',
}).pipe((s) => ({ }).pipe((s) => ({
__prod__: s.NODE_ENV === "production", __prod__: s.NODE_ENV === "production",
environment: s.NODE_ENV, environment: s.NODE_ENV,
@ -43,6 +44,7 @@ const envSchema = type({
migrationsPath: s.MIGRATIONS_PATH, migrationsPath: s.MIGRATIONS_PATH,
appVersion: s.APP_VERSION, appVersion: s.APP_VERSION,
trustedOrigins: s.TRUSTED_ORIGINS?.split(",").map((origin) => origin.trim()), trustedOrigins: s.TRUSTED_ORIGINS?.split(",").map((origin) => origin.trim()),
disableRateLimiting: s.DISABLE_RATE_LIMITING === "true",
})); }));
const parseConfig = (env: unknown) => { const parseConfig = (env: unknown) => {

View file

@ -47,6 +47,8 @@ services:
target: production target: production
container_name: zerobyte container_name: zerobyte
restart: unless-stopped restart: unless-stopped
environment:
- DISABLE_RATE_LIMITING=true
devices: devices:
- /dev/fuse:/dev/fuse - /dev/fuse:/dev/fuse
cap_add: cap_add:

View file

@ -7,6 +7,7 @@ import { createTestAccount } from "./helpers/account";
test.describe.configure({ mode: "serial" }); test.describe.configure({ mode: "serial" });
test.beforeEach(async () => { test.beforeEach(async () => {
console.log("Resetting database...");
await resetDatabase(); await resetDatabase();
}); });
@ -73,5 +74,5 @@ test("can't create another admin user after initial setup", async ({ page }) =>
await page.getByRole("button", { name: "Create admin user" }).click(); await page.getByRole("button", { name: "Create admin user" }).click();
await expect(page.getByText("Admin user already exists")).toBeVisible(); await expect(page.getByText("Failed to create admin user")).toBeVisible();
}); });

View file

@ -9,14 +9,12 @@ const sqlite = createClient({ url: `file:${path.join(process.cwd(), "data", DATA
export const db = drizzle({ client: sqlite, schema: schema }); export const db = drizzle({ client: sqlite, schema: schema });
export const resetDatabase = async () => { export const resetDatabase = async () => {
for (const table of Object.values(schema)) { const cursor = await sqlite.execute("SELECT name FROM sqlite_master WHERE type='table'");
if ("getSQL" in table) { const tables = cursor.rows
await db .map((row) => row.name)
.delete(table) .filter((name) => name !== "sqlite_sequence" && name !== "__drizzle_migrations") as string[];
.execute()
.catch(() => { for (const table of tables) {
/* Ignore errors */ await sqlite.execute(`DELETE FROM ${table}`);
});
}
} }
}; };