| 1 | import { describe, expect, it } from 'vitest'; |
| 2 | |
| 3 | import { clientIp } |
| 4 | |
| 5 | describe('clientIp', () |
| 6 | it('reads X-Real-IP on Railway and ignores X-Forwarded-For there', |
| 7 | expect( |
| 8 | clientIp( |
| 9 | { |
| 10 | headers: { 'x-real-ip': |
| 11 | ip: '10.0.0.1', |
| 12 | }, |
| 13 | true, |
| 14 | ), |
| 15 | ).toBe('1.1.1.1' |
| 16 | }); |
| 17 | |
| 18 | it('leaves the headers to trust proxy elsewhere', |
| 19 | expect( |
| 20 | clientIp( |
| 21 | { |
| 22 | headers: { 'x-real-ip': |
| 23 | ip: '10.0.0.1', |
| 24 | }, |
| 25 | false, |
| 26 | ), |
| 27 | ).toBe('10.0.0.1' |
| 28 | }); |
| 29 | |
| 30 | it('falls back to the socket address without a header', |
| 31 | expect(clientIp({ |
| 32 | }); |
| 33 | }); |