chore: make ip in Context optional

This commit is contained in:
WebStreamr 2025-06-19 11:52:21 +00:00
parent 2d4c5a8221
commit 138e92afc5
No known key found for this signature in database
6 changed files with 11 additions and 10 deletions

View file

@ -29,7 +29,7 @@ export class StreamController {
const ctx: Context = {
id: res.getHeader('X-Request-ID') as string,
ip: req.ip as string,
...(req.ip && { ip: req.ip }),
config,
};

View file

@ -72,7 +72,7 @@ addon.listen(port, () => {
});
const cacheWarmup = async () => {
const ctx = { id: 'warmup', ip: '127.0.0.1', config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' } };
const ctx = { id: 'warmup', config: { de: 'on', en: 'on', es: 'on', fr: 'on', it: 'on', mx: 'on' } };
logger.info(`starting cache warmup`, ctx);
interface ResponsePartial { results: { id: number }[] }

View file

@ -4,7 +4,6 @@ import { getDefaultConfig } from '../utils';
export const createTestContext = (config?: Config): Context => {
return {
id: 'test',
ip: '0.0.0.0',
config: config ?? getDefaultConfig(),
};
};

View file

@ -2,7 +2,7 @@ import { Manifest, ManifestConfig } from 'stremio-addon-sdk';
export interface Context {
id: string;
ip: string;
ip?: string;
config: Config;
}

View file

@ -8,7 +8,7 @@ fetchMock.mockGlobal();
const fetcher = new Fetcher(winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }));
describe('fetch', () => {
const ctx = createTestContext();
const ctx = { ...createTestContext(), ip: '0.0.0.0' };
afterEach(() => {
fetchMock.clearHistory();

View file

@ -91,13 +91,15 @@ export class Fetcher {
headers: {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en',
...(cookieString && { Cookie: cookieString }),
'Forwarded': `for=${ctx.ip}`,
'Priority': 'u=0',
'User-Agent': this.hostUserAgentMap.get(url.host) ?? 'node',
'X-Forwarded-For': ctx.ip,
'X-Forwarded-Proto': url.protocol.slice(0, -1),
'X-Real-IP': ctx.ip,
...(cookieString && { Cookie: cookieString }),
...(ctx.ip && {
'Forwarded': `for=${ctx.ip}`,
'X-Forwarded-For': ctx.ip,
'X-Forwarded-Proto': url.protocol.slice(0, -1),
'X-Real-IP': ctx.ip,
}),
...init?.headers,
},
};