Files
pchelpmaster/tests/lint/pb-dev-proxy.spec.ts
T
kamaskandClaude Sonnet 5.5 bf72af9ef4 feat(dev): proxy /pb to PocketBase in ng serve
Add proxy.conf.mjs mirroring `location /pb/` from nginx: the prefix is
stripped, target comes from PB_URL (empty value falls back to the default,
same as the SSR provider). Cover the config with tests in tests/lint and
update docs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-31 20:24:13 +03:00

37 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Проверяет правило `/pb/` в proxy.conf.mjs: оно должно повторять `location /pb/` из nginx и серверный `PB_URL`.
import { afterEach, describe, expect, it, vi } from 'vitest';
type Rules = typeof import('../../proxy.conf.mjs').default;
async function loadRules(pbUrl: string | undefined): Promise<Rules> {
vi.stubEnv('PB_URL', pbUrl);
vi.resetModules();
return (await import('../../proxy.conf.mjs')).default;
}
describe('прокси /pb для ng serve', () => {
afterEach(() => vi.unstubAllEnvs());
it('содержит правило /pb/ с target из PB_URL', async () => {
const rules = await loadRules('http://pb.test:1234');
expect(rules['/pb/']?.target).toBe('http://pb.test:1234');
expect(rules['/pb/']?.changeOrigin).toBe(true);
});
it.each([undefined, ''])('при PB_URL=%j target — http://127.0.0.1:8090', async (pbUrl) => {
const rules = await loadRules(pbUrl);
expect(rules['/pb/']?.target).toBe('http://127.0.0.1:8090');
});
it('rewrite срезает префикс /pb', async () => {
const rewrite = (await loadRules(undefined))['/pb/']?.rewrite;
expect(rewrite?.('/pb/api/health')).toBe('/api/health');
expect(rewrite?.('/pb/api/collections/x/records?a=1')).toBe(
'/api/collections/x/records?a=1',
);
});
});