diff --git a/lib/app.tsx b/lib/app-bootstrap.tsx similarity index 97% rename from lib/app.tsx rename to lib/app-bootstrap.tsx index 2747dcfd2..f8b9215e3 100644 --- a/lib/app.tsx +++ b/lib/app-bootstrap.tsx @@ -1,5 +1,3 @@ -import '@/utils/request-rewriter'; - import { Hono } from 'hono'; import { compress } from 'hono/compress'; diff --git a/lib/app.test.ts b/lib/app.test.ts index b81d62ee5..5e69fc872 100644 --- a/lib/app.test.ts +++ b/lib/app.test.ts @@ -1,6 +1,9 @@ -import { describe, expect, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import app from '@/app'; +import undici from 'undici'; + +const { config } = await import('@/config'); describe('index', () => { it('serve index', async () => { @@ -9,3 +12,14 @@ describe('index', () => { expect(await res.text()).toContain('Welcome to RSSHub!'); }); }); + +describe('request-rewriter', () => { + it('should rewrite request', async () => { + const fetchSpy = vi.spyOn(undici, 'fetch'); + await app.request('/test/httperror'); + + // headers + const headers: Headers = fetchSpy.mock.lastCall?.[0].headers; + expect(headers.get('user-agent')).toBe(config.ua); + }); +}); diff --git a/lib/app.ts b/lib/app.ts new file mode 100644 index 000000000..84ec9c741 --- /dev/null +++ b/lib/app.ts @@ -0,0 +1,5 @@ +// This file ensures that the request rewriter runs before the app + +import '@/utils/request-rewriter'; + +export default (await import('./app-bootstrap')).default;