Skip to content

Commit d440127

Browse files
committed
fix: Increase rate limit for localhost/Docker testing
Fixes HTTP 429 errors during test suite execution by allowing 10,000 requests per 15 minutes for localhost and Docker network IPs, while maintaining 100 requests for external IPs. Changes: - Rate limit: 10,000 for localhost/Docker (127.0.0.1, ::1, ::ffff:172.x.x.x) - Rate limit: 100 for external IPs (security maintained) - Fix make_calendar tool to properly construct calendar URLs
1 parent 3292de9 commit d440127

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ app.use(cors({
3535
credentials: true,
3636
}));
3737

38-
// Rate Limiting
38+
// Rate Limiting - Higher limits for localhost/Docker testing
3939
const limiter = rateLimit({
4040
windowMs: 15 * 60 * 1000, // 15 minutes
41-
max: 100, // Limit each IP to 100 requests per windowMs
41+
max: (req) => {
42+
// Allow higher rate limit for localhost and Docker networks (for testing)
43+
const ip = req.ip || req.connection.remoteAddress;
44+
if (ip === '127.0.0.1' || ip === '::1' || ip === '::ffff:127.0.0.1' || ip?.startsWith('::ffff:172.')) {
45+
return 10000; // 10000 requests for local/Docker networks
46+
}
47+
return 100; // 100 requests for external IPs
48+
},
4249
message: 'Too many requests from this IP, please try again later.',
4350
standardHeaders: true,
4451
legacyHeaders: false,

src/tools.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,39 @@ END:VCALENDAR`;
406406
const validated = validateInput(makeCalendarSchema, args);
407407
const client = tsdavManager.getCalDavClient();
408408

409+
// Get existing calendars to find the calendar home URL
410+
const calendars = await client.fetchCalendars();
411+
412+
if (!calendars || calendars.length === 0) {
413+
throw new Error('Cannot create calendar: No calendar home found. Please ensure you have at least one calendar or proper CalDAV permissions.');
414+
}
415+
416+
// Extract calendar home from an existing calendar URL
417+
// Example: https://dav.example.com/calendars/user/calendar-name/ -> https://dav.example.com/calendars/user/
418+
const existingCalendarUrl = calendars[0].url;
419+
const calendarHome = existingCalendarUrl.substring(0, existingCalendarUrl.lastIndexOf('/', existingCalendarUrl.length - 2) + 1);
420+
421+
// Generate new calendar URL with sanitized name
422+
const sanitizedName = validated.display_name
423+
.toLowerCase()
424+
.replace(/[^a-z0-9-]/g, '-')
425+
.replace(/-+/g, '-')
426+
.replace(/^-|-$/g, '');
427+
const newCalendarUrl = `${calendarHome}${sanitizedName}-${Date.now()}/`;
428+
409429
const calendar = await client.makeCalendar({
410-
displayName: validated.display_name,
411-
description: validated.description,
412-
calendarColor: validated.color,
413-
timezone: validated.timezone,
430+
url: newCalendarUrl,
431+
props: {
432+
displayName: validated.display_name,
433+
description: validated.description,
434+
calendarColor: validated.color,
435+
timezone: validated.timezone,
436+
}
414437
});
415438

416439
return formatSuccess('Calendar created successfully', {
417-
displayName: calendar.displayName,
418-
url: calendar.url,
440+
displayName: validated.display_name,
441+
url: newCalendarUrl,
419442
});
420443
},
421444
},

0 commit comments

Comments
 (0)